在某些Android 4上,使用appcompat庫不應用主題。X設備

[英]Theme not applied using appcompat library on some Android 4.X devices


After updating the appcompat library to the latest version (v21) to apply the material design, my custom theme isn't used anymore on Android 4.0.X devices unless I explicitly declare it in the XML.

在將appcompat庫更新到最新版本(v21)以應用材料設計之后,我的自定義主題不再在Android 4.0中使用。X設備,除非我在XML中顯式地聲明它。

I have tested the theme on Android 2.3.X and 5.0.0 devices and it works on those devices. But it's not working on my HTC One S with Android 4.0.3. What do I need to do to fix this?

我已經在Android 2.3上測試過這個主題。X和5。0設備在這些設備上工作。但是我的HTC One和Android 4.0.3不兼容。我需要做什么來解決這個問題?

My themes.xml

我themes.xml

<style name="Theme.Custom" parent="@style/Theme.AppCompat.Light">
    <item name="android:editTextStyle">@style/Custom.Widget.EditText</item>
    <item name="android:buttonStyle">@style/Custom.Widget.Button</item>
</style>

My styles.xml

我styles.xml

<style name="Custom.Widget.EditText" parent="android:Widget.EditText">
    <item name="android:background">@drawable/edit_text_holo_light</item>
    <item name="android:textColor">@color/text_primary</item>
    <item name="android:textColorHint">@color/text_hint_color</item>
</style>

<style name="Custom.Widget.Button" parent="android:Widget.Button">
    <item name="android:background">@drawable/btn_default_holo_light</item>
    <item name="android:minHeight">48dip</item>
    <item name="android:minWidth">64dip</item>
    <item name="android:textColor">@color/button_text_primary</item>
</style>

My layout file

我的布局文件

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal" >

    <!-- other elements -->

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp" >

        <EditText
            android:id="@+id/view_username_edit_username_editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textNoSuggestions|textCapSentences"
            android:hint="@string/UsernameScreen_usernameHint"
            android:imeOptions="actionDone"
            android:singleLine="true"
            android:maxLength="@integer/username_max_length"
            android:textSize="@dimen/text_size_medium" />

        <Button
            android:id="@+id/view_username_save_Button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/view_username_edit_username_editText"
            android:clickable="true"
            android:enabled="false"
            android:orientation="horizontal"
            android:text="@string/common_save" />
    </RelativeLayout>

</RelativeLayout>

If I add the following to lines in the layout files it works. So there seems to be going something wrong with the themes.xml.

如果我在布局文件中添加以下行,它就可以工作。因此題目。xml似乎出了問題。

style="@style/Custom.Widget.EditText"
style="@style/Custom.Widget.Button"

Result:

結果:

Result

Expected:

預期:

Expected

Edit

編輯

I tested the same code on some other devices.

我在其他設備上測試了相同的代碼。

  • Samsung S2 (4.0.4): OK
  • 三星S2(4.0.4):好的
  • HTC One (4.4.3): OK
  • HTC(4.4.3):好的
  • HTC One X (4.0.3): NOK
  • HTC One X (4.0.3): NOK
  • HTC One S (4.1.1): NOK
  • HTC One S (4.1.1): NOK
  • HTC Desire C (4.0.3): NOK
  • HTC Desire C (4.0.3): NOK

I don't see why it wouldn't work on some of these devices.

我不明白為什么它不能在這些設備上工作。

2 个解决方案

#1


4  

I after add buttonStyle without the "android:" prefix and it solved the problem. (name="android:buttonStyle" -> name="buttonStyle")

我添加了沒有“android:”前綴的buttonStyle,解決了問題。(name = " android:buttonStyle " - > name = " buttonStyle ")

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="buttonStyle">@style/SkinedButton</item>
</style>

#2


0  

Finally I found a solution to my problem. I was using @style/Theme.AppCompat as a parent to one of my styles. After changing it to @style/Theme.AppCompat.Light.DarkActionBar it works on all devices. I still find it very strange why this would screw up my styling.

我終於找到了解決我問題的辦法。我用@style /主題。AppCompat作為我的一個風格的父母。將其更改為@style/Theme.AppCompat.Light。它適用於所有設備。我仍然覺得很奇怪為什么這會搞砸我的造型。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/12/22/724efae28ff1bdcb5a2120f4e1278503.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com