一、别人怎么做

来源

http://stackoverflow.com/questions/3078081/setting-global-styles-for-views-in-android
Actually, you can set a default style for TextViews (and most other built-in widgets) without needing to do a custom java class or setting the style individually.

If you take a look in themes.xml in the Android source, you will see a bunch of attributes for the default style for various widgets. The key is the textViewStyle (or editTextStyle, etc.) attribute which you override in your custom theme. You can override these in the following way:

Create a styles.xml:

<?xml version="1.0" encoding="utf-8"?><resources>    <style name="MyTheme" parent="android:Theme">        <item name="android:textViewStyle">@style/MyTextViewStyle    style>    <style name="MyTextViewStyle" parent="android:Widget.TextView">        <item name="android:textColor">#F00item>        <item name="android:textStyle">bolditem>    style>resources> 

Then just apply that theme to your application in AndroidManifest.xml:

<application […] android:theme="@style/MyTheme">

And all your text views will default to the style defined in MyTextViewStyle (in this instance, bold and red)!

This was tested on devices from API level 4 onward and seems to work great.

结论

    

测试可行

二、自测可行的另一种方式

        <item name="android:textColorPrimary">@color/text_color_defaultitem>        <item name="android:textColorSecondary">@color/text_color_defaultitem>        <item name="android:textColorTertiary">@color/text_color_defaultitem>

三、遇到的问题

 使用过程中,发现这个全局style对ListView中的TextView不生效

解决方案

不适用getApplicationContext,改使用Activity

//adapter = new ShopResultAdapter(getApplicationContext(), datas);//替换为Activityadapter = new ShopResultAdapter(this, datas);

更多相关文章

  1. Android(安卓)开发常用代码片段
  2. RxJava在Android的应用场景
  3. android dialog使用小结
  4. Android(安卓)使用AlarmManager设置闹钟
  5. Android(安卓)学习--ListView 的使用(三)
  6. Android(安卓)NDK之----- C调用Java [GetMethodID方法的使用]
  7. 箭头函数的基础使用
  8. NPM 和webpack 的基础使用
  9. Python list sort方法的具体使用

随机推荐

  1. Android引入广播机制的用意。单线程模型M
  2. Android(安卓)App 启动流程梳理(基于 Andr
  3. Android工程的编译过程
  4. Android(安卓)应用开发笔记 - Android的
  5. Android中微信主界面菜单栏的布局实现代
  6. Android(安卓)Material Design 系列之 Se
  7. Android菜鸟的成长笔记(14)—— Android中
  8. Android群英传笔记——第六章:Android绘图
  9. Android中文翻译组 - 简介
  10. android UI进阶之android中隐藏的layout