使用部分Android 4.X设备应用程序兼容性库没有应用主题 [英] Theme not applied using appcompat library on some Android 4.X devices
问题描述
在应用程序兼容性更新库到最新版本(V21)申请材料的设计之后,我的自定义主题不再使用在Android 4.0.X的设备,除非我明确声明它的XML。
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.
我已经测试在Android 2.3.x版本5.0.0和设备上的主题和它的作品在这些设备上。但它不工作在我的Android 4.0.3的HTC One秒。我需要做什么做解决这一问题?
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?
我的themes.xml
My 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>
我的styles.xml
My 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>
如果我添加以下内容到它的工作原理布局文件行。所以,似乎是想有点毛病的themes.xml。
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.
style="@style/Custom.Widget.EditText"
style="@style/Custom.Widget.Button"
结果:
预期:
修改
我测试了一些其他设备相同code。
I tested the same code on some other devices.
- 三星S2(4.0.4):确定
- 的HTC One(4.4.3):确定
- 的HTC One X(4.0.3):NOK
- 的HTC One S(4.1.1):NOK
- 的HTC Desire C(4.0.3):NOK
我不明白为什么它不会对这些设备的一些工作。
I don't see why it wouldn't work on some of these devices.
推荐答案
最后,我找到了解决我的问题。我使用 @风格/ Theme.AppCompat
作为家长的我的风格之一。将其更改为 @风格/ Theme.AppCompat.Light.DarkActionBar后
它适用于所有设备。我仍然觉得很奇怪,为什么会搞砸了我的风格。
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.
这篇关于使用部分Android 4.X设备应用程序兼容性库没有应用主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!