简体   繁体   English

Android-不同设备上的不同背景

[英]Android - different background on different devices

I have my own theme. 我有自己的主题。 It works fine on Android 5+ (buttons' background is black as I defined, black activity background, buttons' text color). 它在Android 5+上运行良好(按钮的背景为我定义的黑色,黑色活动背景,按钮的文本颜色)。 All colors are defined correctly. 正确定义了所有颜色。

But on Android 4 buttons' background is white (like standard theme) (everything another is ok). 但是在Android 4上,按钮的背景是白色(就像标准主题一样)(其他都可以)。 I have no idea why. 我不知道为什么。 Button: 按键:

 <Button
        android:layout_width="303dp"
        android:layout_height="wrap_content"
        android:text="@string/auth_button"
        android:id="@+id/auth_endwork_button"
        android:padding="@dimen/activity_horizontal_margin"
        android:layout_gravity="center_horizontal"/>

style.xml style.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:colorForeground">@color/textColorSecondary</item>
        <item name="android:colorBackground">@color/colorBackground</item>
        <item name="android:textColor">@color/textColorPrimary</item>
        <item name="android:textColorPrimary">@color/textColorPrimary</item>
        <item name="android:windowBackground">@color/windowBackground</item>
        <item name="android:itemBackground">@color/colorBackground</item>
        <item name="android:buttonStyle">@style/ButtonText</item>
        <item name="android:editTextStyle">@style/EditTextStyle</item>
    </style>

    <style name="EditTextStyle" parent="android:style/Widget.EditText">
        <item name="android:textColor">@color/textColorPrimary</item>
        <item name="android:background">@color/colorBackground</item>
    </style>

    <style name="ButtonText" parent="@android:style/Widget.Button">
        <item name="android:background">@drawable/button_style</item>
        <item name="android:textColor">@color/text_color</item>
        <item name="android:padding">0dp</item>
        <item name="android:minWidth">88dp</item>
        <item name="android:minHeight">36dp</item>
        <item name="android:layout_margin">3dp</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>

Button style: 按钮样式:

    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:drawable="@color/buttonPressed" /> <!-- pressed -->
    <item android:drawable="@color/colorPrimary" /> <!-- default (not pressed) -->
</selector>

Colors: 颜色:

    <?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#FF212121</color>
    <color name="colorPrimaryDark">#FF000000</color>
    <color name="colorAccent">#FF80CBC4</color>
    <color name="colorBackground">#FF303030</color>
    <color name="textColorPrimary">#FFFFFFFF</color>
    <color name="textColorSecondary">#FFFFFFFF</color>
    <color name="windowBackground">#FF303030</color>
    <color name="buttonPressed">#FF3B3B3B</color>
    <color name="buttonDisabled">#83868a</color>
</resources>

I'm no expert. 我不是专家。 But could it be related to the AppCompat changes between 4 and 5? 但这可能与AppCompat在4到5之间的变化有关吗?

[AppVompat v21 - Material Design for pre-Lolipop] http://android-developers.blogspot.se/2014/10/appcompat-v21-material-design-for-pre.html 1 [AppVompat v21-棒棒糖之前的材料设计] http://android-developers.blogspot.se/2014/10/appcompat-v21-material-design-for-pre.html 1

In

<item name="android:buttonStyle">@style/ButtonText</item>

Remove "android:" 删除“ android:”

    <item name="buttonStyle">@style/ButtonText</item>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM