Тема не применяется с использованием библиотеки appcompat на некоторых устройствах Android 4.X
После обновления библиотеки appcompat до последней версии (v21) для применения дизайна материала моя пользовательская тема больше не используется на устройствах Android 4.0.X, если я не объявляю ее явно в XML.
Я тестировал тему на устройствах Android 2.3.X и 5.0.0 и работает на этих устройствах. Но он не работает на моем HTC One S с Android 4.0.3. Что мне нужно сделать, чтобы исправить это?
Мои темы .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>
Мои 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>
Мой файл макета
<?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>
Если я добавлю следующие строки в файлы макета, он будет работать. Так что, похоже, что-то не так с theme.xml.
style="@style/Custom.Widget.EditText"
style="@style/Custom.Widget.Button"
Результат:
![Result]()
Ожидаемое:
![Expected]()
Edit
Я тестировал один и тот же код на некоторых других устройствах.
- Samsung S2 (4.0.4): OK
- HTC One (4.4.3): OK
- HTC One X (4.0.3): NOK
- HTC One S (4.1.1): NOK
- HTC Desire C (4.0.3): NOK
Я не понимаю, почему это не сработает на некоторых из этих устройств.
Ответы
Ответ 1
Наконец, я нашел решение своей проблемы. Я использовал @style/Theme.AppCompat
в качестве родителя для одного из моих стилей. После изменения его на @style/Theme.AppCompat.Light.DarkActionBar
он работает на всех устройствах. Мне все еще очень странно, почему это испортило мой стиль.
Ответ 2
После создания кнопки buttonStyle без префикса "android:" я решил проблему.
(name= "android: buttonStyle" → name= "buttonStyle" )
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="buttonStyle">@style/SkinedButton</item>
</style>