Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android中的主题是混合的_Android_User Interface_Styles - Fatal编程技术网

Android中的主题是混合的

Android中的主题是混合的,android,user-interface,styles,Android,User Interface,Styles,我有一个应用程序,我在主题A中定义主题“A”和“B”,定义一组样式 <resources> <style name="Theme.A" parent="Theme.Base.AppCompat"> </style> <style name="btnMiniPlayer" parent="Theme.A"> <item name="android:background">@drawable/image1</item>

我有一个应用程序,我在主题A中定义主题“A”和“B”,定义一组样式

<resources>
<style name="Theme.A" parent="Theme.Base.AppCompat">
</style>

<style name="btnMiniPlayer" parent="Theme.A">
    <item name="android:background">@drawable/image1</item>
</style>
取决于我需要更改图像的样式,我也在清单中设置了主题,但应用程序正在混合这些样式,所以现在我将“A”设置为与主主题类似,但应用程序显示主题“B”中的图像


有什么想法吗?

做如下事情:

<style name="button" parent="A">
    <item name="android:background">@drawable/image</item>
</style>

我找到了如何回答我的问题,所以你需要按照下面的步骤来解决它

1-创建一个属性在我的例子中,我设置了类似myButton的名称:

<declare-styleable name="def_Styles">
    <attr name="myButton" format="reference" />
</declare-styleable>

如果在A和B之间更改清单中的主题,它将起作用

你是说当某些事件发生时(如按下按钮),你想更改按钮的样式吗?我是说当应用程序启动时,我在清单中设置了主题,但我设置了主题A的样式,但应用程序正在从主题B中选择样式,如果样式具有相同的名称,第二个样式不会覆盖第一个样式吗?在什么条件下需要更改图像?用户在应用程序中有一个选择主题的选项,因此我在运行时更改样式,但默认的应用程序以主题A开始,但是总是把主题中的图片显示给父母@drawable/image1@drawable/image2
<style name="button" parent="A">
    <item name="android:background">@drawable/image</item>
</style>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="false" android:drawable="@drawable/image1" />
    <item android:state_pressed="true" android:drawable="@drawable/image2" />
</selector>
android:state_selected="true" 
<declare-styleable name="def_Styles">
    <attr name="myButton" format="reference" />
</declare-styleable>
<resources>
<style name="Theme.B" parent="Theme.Base.AppCompat">
    <item name="myButton">@style/CustomButtonB</item>
</style>

<style name="CustomButtonB" parent="Theme.B">
    <item name="android:background">@drawable/image2</item>
</style>
style="?myButton"