我爱编程

夜间模式时字体颜色转换的设置

2018-07-26  本文已影响0人  Rhett_yu

首先在styles.xml设置主题夜间日间

<style name="AppTheme_Night" parent="mainActivity">
<style name="AppTheme_Day" parent="mainActivity">

并且manifest.xml中得应用

android:theme="@style/mainActivity"
1,先在attrs.xm设置字段string 例如:

l<attr name="text_search" format="color" />

2,在styles.xml中对应的夜间和日间设置对应的颜色

例如
日间:
<item name="cancle_search">@color/text_search_color</item>
夜间:
<item name="cancle_search">@color/text_search_color</item>

3,在color.xml中设置颜色
日间:
<color name="text_search_color">#ebebeb</color>
夜间:
<color name="text_search_color">#ffffff</color>

4,在到class中设置

TypedValue title_btn = new TypedValue();
Resources.Theme theme = mContext.getTheme();
theme.resolveAttribute(R.attr.search_tv_bg, title_btn , true);

5,然后设置字体颜色

v.setTextColor(resources.getColor(title_btn .resourceId));
6,xml中

android:textColor="?attr/cancle_search"

上一篇 下一篇

猜你喜欢

热点阅读