简体   繁体   English

如何动态更改整个android应用的字体颜色?

[英]How would I dynamically change the font color for a whole android app?

I have my styles.xml file for the app: 我有该应用程序的styles.xml文件:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColor">#000000</item>
    <item name="android:background">#FFFFFF</item>
</style>

I want to make it so that if a user selects a value from a spinner then that value changes the textColor in the styles app. 我想这样做,以便如果用户从微调器中选择一个值,则该值会更改样式应用程序中的textColor。

I have my onClick method and I have the value from the spinner but I can't figure out how I access the textColor styles item and how I dynamically change it? 我有我的onClick方法,也有旋转器的值,但是我不知道如何访问textColor样式项以及如何动态更改它?

I didn't manage to do exactly what I wanted but a workaround was that I only let the user choose between 3 font colours: black, blue, and red, and then I had 3 themes. 我没有完全按照自己的意愿进行操作,但是一种解决方法是,我只允许用户在3种字体颜色之间进行选择:黑色,蓝色和红色,然后才有3个主题。 Each theme had the different text colour. 每个主题都有不同的文本颜色。

Then I just switched the theme following this answer: Android - Change app Theme on onClick 然后我按照以下答案切换了主题: Android-onClick更改应用主题

One way to achieve this is to make a color.xml resource in the rescourses folder and link to it in the activity layout. 实现此目的的一种方法是在rescourses文件夹中创建color.xml资源,并在活动布局中链接至该资源。

Also why do you have css as one of the tags for this question? 另外,为什么要使用CSS作为此问题的标签之一?

Rather it should be XML. 而是应该是XML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM