Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.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 基于应用程序主题名称的应用程序主题、更改和ImageView src_Android_Themes_Android Imageview - Fatal编程技术网

Android 基于应用程序主题名称的应用程序主题、更改和ImageView src

Android 基于应用程序主题名称的应用程序主题、更改和ImageView src,android,themes,android-imageview,Android,Themes,Android Imageview,我正试图找到解决问题的办法,但我哪儿都找不到,甚至在谷歌上也找不到 我正在编写一个android应用程序,它使用主题,用户可以手动切换主题,然后重新启动应用程序以应用所选主题。这很有效 但是,我找不到基于所选主题更改imageview元素的方法。我无法理解android应用程序使用主题的方式,我无法手动更改文件,只能更改应用程序对象中的主题名称,在主题样式标记中,我无法指定单个imageview的src 我也可以仅使用windowbackground属性来满足我的应用程序要求。但是,我不能使用s

我正试图找到解决问题的办法,但我哪儿都找不到,甚至在谷歌上也找不到

我正在编写一个android应用程序,它使用主题,用户可以手动切换主题,然后重新启动应用程序以应用所选主题。这很有效

但是,我找不到基于所选主题更改imageview元素的方法。我无法理解android应用程序使用主题的方式,我无法手动更改文件,只能更改应用程序对象中的主题名称,在主题样式标记中,我无法指定单个imageview的src

我也可以仅使用windowbackground属性来满足我的应用程序要求。但是,我不能使用scaletype属性使其按比例拉伸,也不能在bitmapdrawable中使用重力,我不知道如何在保持图像比例的窗口内使其减小


感谢所有回答我问题的人,并为我的英语道歉!:)

最近,我要求根据主题更改
ImageView
图片。我使用的是
ExpandableListView
ImageView
作为 组指示器,而不是现成的组指示器。因为我的应用程序支持明暗主题,所以我想将组指示器、操作栏图标切换到明暗版本

以下是如何:

res/values/attrs.xml
文件中声明要根据主题更改的每个ImageView或ActionBar图标的自定义属性:

<declare-styleable name="customAttrs">
    <attr name="actionSearchIcon" format="reference" />
    <attr name="actionAcceptIcon" format="reference" />
    <attr name="actionRefreshIcon" format="reference" />
    <attr name="groupIndicatorIcon" format="reference" />
</declare-styleable>
最后,在实际布局中,将相关属性指向您定义的属性,而不是直接指向可绘图项。例如 对于操作栏图标:

<item
android:id="@+id/action_refresh"
android:icon="?attr/actionRefreshIcon"
android:orderInCategory="107"
android:title="@string/action_refresh"
app:showAsAction="always"/>

<item
android:id="@+id/action_accept"
android:icon="?attr/actionAcceptIcon"
android:orderInCategory="108"
android:title="@string/action_accept"
app:showAsAction="always"/>

<item
android:id="@+id/action_search"
android:icon="?attr/actionSearchIcon"
android:orderInCategory="50"
android:title="@string/action_search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="collapseActionView|always"/>

或者,对于ImageView:

<ImageView
android:id="@+id/group_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:contentDescription="@string/app_name"
android:src="?attr/groupIndicatorIcon"/>


令人兴奋的是,这个概念可以应用于任何控件或任何属性:)

您找到了解决方案吗?我也有类似的要求。在我们的项目中尝试了这种方法,效果很好。谢谢
<ImageView
android:id="@+id/group_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:contentDescription="@string/app_name"
android:src="?attr/groupIndicatorIcon"/>