Android上的Snackbar,无需更改主题 [英] Snackbar on Android without changing theme

查看:135
本文介绍了Android上的Snackbar,无需更改主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Android上创建快餐栏时,出现以下错误: "java.lang.IllegalStateException:您需要在此活动中使用Theme.AppCompat主题(或后代)."

When I create a snackbar on Android I get this error: "java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity".

我不想将活动的主题更改为AppCompat,是否可以在不更改主题的情况下使用小吃店?

I don't want to change the theme to AppCompat of my activity, Is there a way I can have the snackbar without changing the theme?

推荐答案

您正在使用appcompat-v7(AppCompatActivityTheme.AppCompat等),还是没有使用.您需要保持一致,因此,如果您不打算使用Theme.AppCompat,请确保您没有扩展AppCompatActivity.

Either you are using appcompat-v7 (AppCompatActivity, Theme.AppCompat, etc.), or you are not. You need to be consistent, so if you are not going to use Theme.AppCompat, make sure you are not extending AppCompatActivity.

但是,设计支持库— 官方Snackbar 的来源—仅支持使用appcompat-v7的活动.如果想要不带appcompat-v7的快餐栏,则不能使用设计支持库.相反,请使用快餐栏的其他实现.

However, the Design Support library — the source of the official Snackbar — only supports activities using appcompat-v7. If you want a snackbar without appcompat-v7, you cannot use the Design Support library. Instead, use some other implementation of a snackbar.

我刚刚发布了一个,该库提供了可以正常使用的官方Snackbar的端口没有appcompat-v7的情况,但仅适用于minSdkVersion为21或更高的项目. 此库实现了一个快餐栏,可在较旧的设备上使用,尽管该项目已终止.可能还有其他实现方式.

I just released a library that offers a port of the official Snackbar that works without appcompat-v7, but it only works with projects that have minSdkVersion of 21 or higher. This library implements a snackbar that works on older devices, though the project is discontinued. There may be other implementations.

这篇关于Android上的Snackbar,无需更改主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆