在我使用 AutoCompleteEditText 和 ChipGroup 创建布局后,我试图在我的 Android 应用程序中创建一个 ChipInput,我将动态创建的 Chip 添加到其中,但在堆栈跟踪中出现以下错误:
E/ThemeUtils:视图类 com.google.android.material.chip.Chip 是一个 AppCompat 小部件,只能与 Theme.AppCompat 主题(或后代)一起使用。
此组件上的样式要求您的应用程序主题为 Theme.MaterialComponents(或其后代)。
问题是我的主题尚未设置为材质,但我仍然收到该错误,我什至尝试以编程方式将主题设置为芯片,但仍然出现该错误。
这是我以编程方式添加芯片的代码
private fun addChipToGroup(person: String, chipGroup: ChipGroup) {
val chip = Chip(applicationContext)
chip.text = person
chip.isCloseIconVisible = true
// necessary to get single selection working
chip.isClickable = true
chip.isCheckable = false
chipGroup.addView(chip as View)
chip.setOnCloseIconClickListener { chipGroup.removeView(chip as View) }
}
Run Code Online (Sandbox Code Playgroud)
应用程序在该方法的第一行崩溃
android android-theme kotlin android-chips material-components-android
我正在为旧版本的Android开发并使用PreferenceActivity(我知道这PreferenceFragment是正确的方法).
我PreferenceActivity正在采用我的应用程序的主题,但我希望它采取一般设置主题是什么.我该怎么做呢?
我有一个actionBarStyle我在我的应用程序中为我实现的ActionBar.这是下面的xml代码:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyActionBarTheme" parent="@android:style/Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:actionBarStyle">@style/MyCustomActionBar</item>
</style>
<style name="MyCustomActionBar" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">@android:color/transparent</item>
<item name="android:backgroundSplit">@android:color/transparent</item>
<item name="android:displayOptions">useLogo</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这是我的Activity OnCreate:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setLogo(R.drawable.ic_logo);
setContentView(R.layout.activity_home);
initializeViews();
manageFragments();
}
Run Code Online (Sandbox Code Playgroud)
问题是我ActionBar根本没有显示,当我displayOptions从My XML中删除项目时.它显示标题.现在我可以随时删除标题(将标题字符串设置为空白)但我不希望这样,因为它显示默认ActionBar样式/主题几秒钟然后我的自定义主题(我猜你知道这个).我不知道问题是什么.请帮忙.谢谢...
android android-theme graphical-logo android-actionbar android-styles
我按照本指南来设置ActionBar的样式.我在我的应用程序中使用固定标签,所以我也想要标签.
(注意:我正在使用appcompat主题来确保一些向后兼容性)
所以我用过
<style
name="CustomTheme"
parent="@style/Theme.AppCompat.Light" >
<item name="android:actionBarStyle">@style/CustomActionBar</item>
<item name="actionBarStyle">@style/CustomActionBar</item>
<item name="android:actionBarTabStyle">@style/CustomActionBarTabs</item>
<item name="actionBarTabStyle">@style/CustomActionBarTabs</item>
</style>
Run Code Online (Sandbox Code Playgroud)
作为我的主题.
我没有问题地设置ActionBar背景,但后来我尝试使用以下标签来标记:
<style
name="CustomActionBarTabs"
parent="@style/Widget.AppCompat.ActionBar.TabView" >
<item name="android:background">@drawable/customtheme_actionbar_tab_indicator</item>
<item name="background">@drawable/customtheme_actionbar_tab_indicator</item>
</style>
Run Code Online (Sandbox Code Playgroud)
背景指向一个StateList,我为不同的上下文设置了不同的drawable,它按预期工作.除了它的工作只是为标签.不适用于ActionBar.
标签栏的分隔符和背景不是主题.
我怎么能主题那些?(灰色部分)

我想知道是否有任何指导方针可以创建一个看起来不错的主题?
(好=类似于默认主题,所以应用程序适合Android生态系统)

因为如果仔细查看默认主题,可以在ActionBar drawable底部看到一个小行.(在我的主题中是浅绿色的部分)
在创建看起来类似于默认主题的主题时,您可能应该考虑其他事项,因此对某些指南会很好.
另外:TabBar应该总是比ActionBar更暗吗?
(如果是这样,有多深?)
图像颜色(如图像中溢出按钮的颜色)应该比ActionBar颜色更亮/更暗?
在此先感谢,
Uriel
android android-theme android-actionbar android-tabs android-actionbar-compat
我一直在尝试按照这些说明实现Material Design主题.
ToolBar(我必须吗?)getSupportActionBar()整个项目.<application>标签包含android:theme="@style/AppTheme"我的styles.xml:
<style name="AppBaseTheme" parent="@style/Theme.AppCompat">
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
<item name="displayOptions">useLogo|showHome</item>
<item name="logo">@drawable/home_page_logo</item>
<item name="background">@color/actionbar_background_color</item>
<item name="textColor">@color/white</item>
<item name="titleTextStyle">@style/MyActionBarTextStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)
无论我尝试了什么,应用程序崩溃第二次我onCreate()使用此崩溃日志启动我的主要活动:
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this …Run Code Online (Sandbox Code Playgroud) 所以,我有这个奇怪的问题:我的应用程序非常简单,主要活动只有一个按钮和清单中设置的活动的自定义主题.
我可以确认主题是否有效并且被选中,因为我可以更改活动背景或字体颜色,例如
但是,当我尝试在我的活动上设置所有按钮的样式时,它不起作用!
这是我使用的styles.xml代码:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:background">#0f0</item>
<item name="android:buttonStyle">@style/btxs</item>
</style>
<style name="btxs" parent="@android:style/Widget.Button">
<item name="android:textColor">#f00</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
活动背景为绿色(主题有效),但按钮仍然是默认值.
是android:buttonStyle在主题设置按钮样式的正确方法是什么?
作为参考,我也粘贴了我的activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_below="@+id/textView"
android:layout_toEndOf="@+id/textView"
android:layout_marginTop="25dp" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) I'm trying to create a dark theme similar to the one in OxygenOS on OnePlus devices.
I changed the window background to black but the problem is the action bar is not becoming pure black.
<style name="DarkTheme" parent="Theme.AppCompact">
<item name="android:colorPrimary">@color/black</item>
<item name="android:colorPrimaryDark">@color/black</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="android:colorAccent">@color/white</item>
<item name="android:color">@color/white</item>
<item name="android:windowBackground">@color/black</item>
<item name="android:navigationBarColor">@color/black</item>
<item name="android:actionBarStyle">@color/black</item>
</style>
Run Code Online (Sandbox Code Playgroud) 我找不到Android 22和23之间不确定ProgressDialog中显示的进度条样式的原因.
我们采取一个非常简单的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="example.com.progressbarcolor.MainActivity">
<Button
android:id="@+id/show_progress"
android:text="Show progres"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:indeterminate="true"
android:visibility="visible"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
按下按钮显示ProgressDialog:
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(false);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();
Run Code Online (Sandbox Code Playgroud)
该应用程序的风格是:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
最后是gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "example.com.progressbarcolor"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0" …Run Code Online (Sandbox Code Playgroud) 我有一些我的EditText放在蓝色背景上,对于这些EditText,我想为文本选择句柄设置一个白色(如果可能的话,在棒棒糖或更新的情况下不上传新的png图像)
我尝试添加<item name="android:colorAccent">#ffffffff</item>我的自定义EditText的样式,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- EditText on a blue background -->
<style name="BlueBGTextView" parent="@android:style/Widget.Material.Light.EditText">
<item name="android:background">@null</item> <!-- this will also remove all paddings -->
<item name="android:textCursorDrawable">@null</item> <!-- this to use android:textColor as the cursor color. -->
<item name="android:colorAccent">#ffffffff</item>
</style>
<!-- default EditText -->
<style name="AppTheme.EditTextStyle" parent="@android:style/Widget.Material.Light.EditText">
<item name="android:background">@null</item> <!-- this will also remove all paddings -->
</style>
<!-- default Theme -->
<style name="AppTheme" parent="@android:style/Theme.Material.Light.NoActionBar">
<item name="android:editTextStyle">@style/AppTheme.EditTextStyle</item>
<item name="android:colorAccent">#ff0288d1</item> <!-- use to setup the color of …Run Code Online (Sandbox Code Playgroud) android textview android-theme android-edittext android-styles
android ×10
android-theme ×10
android-4.0-ice-cream-sandwich ×1
android-tabs ×1
kotlin ×1
material-components-android ×1
textview ×1
themes ×1