标签: android-theme

Material Chip 输入小部件只能与 Theme.AppCompat 一起使用

在我使用 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

3
推荐指数
1
解决办法
1096
查看次数

全息黑暗主题ICS中按钮(正常状态)的颜色值

需要有关HOLO DARK主题ICS中按钮颜色代码的帮助.这个问题为Holo主题的所有颜色代码提供了亮点,除了正常状态下的按钮.提前致谢. 基本按钮全息主题ics.

android android-theme android-4.0-ice-cream-sandwich

2
推荐指数
1
解决办法
3752
查看次数

android:PreferenceActivity主题

我正在为旧版本的Android开发并使用PreferenceActivity(我知道这PreferenceFragment是正确的方法).

PreferenceActivity正在采用我的应用程序的主题,但我希望它采取一般设置主题是什么.我该怎么做呢?

android android-preferences android-theme

2
推荐指数
1
解决办法
1602
查看次数

Android操作栏未在displayOptions上显示 - useLogo

我有一个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

2
推荐指数
1
解决办法
6048
查看次数

主题Android ActionBar:更改TabBar背景

我按照本指南来设置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

2
推荐指数
1
解决办法
6829
查看次数

Lollipop下面的材料设计支持 - 崩溃

我一直在尝试按照这些说明实现Material Design主题.

  • 我没用ToolBar(我必须吗?)
  • 我的所有活动都扩展了ActionBarActivity.
  • 使用getSupportActionBar()整个项目.
  • 我正在使用gradle编译并定位到API 21(最小化是API 15).
  • 我的<application>标签包含android:theme="@style/AppTheme"
  • 在Lollipop设备上运行应用程序(具有特定的v21类似主题).

我的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)

android android-appcompat android-theme material-design

2
推荐指数
1
解决办法
5451
查看次数

为什么android:buttonStyle没有样式按钮?

所以,我有这个奇怪的问题:我的应用程序非常简单,主要活动只有一个按钮和清单中设置的活动的自定义主题.

我可以确认主题是否有效并且被选中,因为我可以更改活动背景或字体颜色,例如

但是,当我尝试在我的活动上设置所有按钮的样式时,它不起作用!

这是我使用的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)

android android-theme android-styles

2
推荐指数
1
解决办法
1914
查看次数

Dark theme android app

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 themes android-theme

2
推荐指数
2
解决办法
1万
查看次数

Android不确定进度对话框进度条样式

我找不到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)

android android-theme

2
推荐指数
1
解决办法
4505
查看次数

如何更改我的EditText之一的文本选择句柄的颜色?

我有一些我的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

2
推荐指数
1
解决办法
1919
查看次数