gpt4 book ai didi

android - 主题、样式和别名嵌套不起作用

转载 作者:行者123 更新时间:2023-12-04 06:22:42 29 4
gpt4 key购买 nike

我正在尝试测试一种制作主题的方法,但我使用的方法并没有给我预期的结果。这是我的设置:

drawable/dummy.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/icon" />

值/mythemes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyOrange" parent="android:style/Theme">
<item name="@drawable/dummy">@style/imgOrange</item>
</style>
<style name="MyBlue" parent="android:style/Theme">
<item name="@drawable/dummy">@style/imgBlue</item>
</style>

<style name="imgOrange">
<item name="android:src">@drawable/orange</item>
</style>
<style name="imgBlue">
<item name="android:src">@drawable/blue</item>
</style>
</resources>

布局/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<ImageView android:id="@+id/imageView1"
android:src="@drawable/dummy"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</ImageView>
</LinearLayout>

我没有收到任何错误,但它也不会改变主题。

我也尝试使用一种样式作为“虚拟”,但它做同样的事情。

任何想法/解释?

最佳答案

我不会假装决定的正确性,但它确实有效。
我用这个技巧解决了这个问题:

我的属性:

<attr name="arrow_up_active" format="reference" />
<attr name="arrow_down_active" format="reference" />

我的主题:
<style name="AppThemeLight" parent="Theme.AppCompat.Light.NoActionBar">
....
<item name="arrow_down_block">@drawable/up_active</item>
<item name="arrow_down_active">@drawable/down_active</item>
</style>
<style name="AppThemeDark" parent="Theme.AppCompat.NoActionBar">
....
<item name="arrow_down_block">@drawable/up_active</item>
<item name="arrow_down_active">@drawable/down_active</item>
</style>

我的变量:
private TypedArray arrowUpActive, arrowDownActive;

宣言:
arrowUpActive = getActivity().getTheme().obtainStyledAttributes(new int[] { R.attr.arrow_up_active });
arrowDownActive = getActivity().getTheme().obtainStyledAttributes(new int[] { R.attr.arrow_down_active });

和用法:
imageButton.setImageDrawable(getResources().getDrawable(arrowUpActive.getResourceId(0,1)));
imageButton.setImageDrawable(getResources().getDrawable(arrowDownActive.getResourceId(0,1)));

关于android - 主题、样式和别名嵌套不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6375804/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com