【问题标题】:ThemeOverlay not showing changes in the preview/design view in Android Studio after update更新后 ThemeOverlay 未在 Android Studio 的预览/设计视图中显示更改
【发布时间】:2018-12-12 20:42:47
【问题描述】:

我最近刚刚更新了我的 Android Studio,从那以后,我在预览/设计编辑器中的按钮上没有显示 ThemeOverlay 属性,这与更新之前一样。但是,当我在设备上运行应用程序时,ThemeOverlay 可以工作。下面是按钮的一些测试代码。我已将按钮的背景属性设置为蓝色,并将按钮的文本设置为测试我

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Test Me"
    android:background="#0000FF"
    android:layout_marginTop="20dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"/>
 </LinearLayout>    

主题属性设置为 TheOverLay.AppCompat.Dark,以便按钮上的文本很亮,但它不会显示在 Android Studio 的设计编辑器/预览中。文本仍显示为深色/黑色。当我在连接的设备上运行它时,它工作正常。 这是因为当前更新发生了一些变化吗?

【问题讨论】:

    标签: android android-studio android-layout


    【解决方案1】:

    您可以在基本主题中设置:
    &lt;item name="android:colorButtonNormal"&gt;@color/some_color&lt;/item&gt; 基本上是全局的,所有按钮都将具有您在主题文件中定义的颜色。

    另一方面,我相信您无法从 ThemeOverlay 获得按钮主题。相反,创建一个新样式并将父级设置为Button

    <style name="CustomButton" parent="Widget.AppCompat.Button.Colored">
    <item name="colorButtonNormal">@color/Red</item>
    <item name="android:colorButtonNormal">@color/Red</item>
    <item name="android:textColor">@color/White</item>
    </style>
    

    您可以将样式应用为: android:theme="@style/CustomButton"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多