最近在开发过程中使用了theme移植Preference并使用了一些android样式,但是在自定义的Theme修改了相关参数后却无法实现

可能有些朋友还不知道怎么用。这里也做个简要的使用方式说明。

1. xml中使用样式。

  1. android:textAppearance="?android:attr/textAppearanceLarge"
    ?android:使用安卓内置样式。
  1. <TextView android:id="@id/title"
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:singleLine="true" android:text="Hellopss"
  5. android:ellipsize="marquee"
  6. android:textAppearance="?android:attr/textAppearanceLarge"
  7. android:fadingEdge="horizontal" />

2.View中使用到xml

  setContentView(xml)

3. 定义Theme

  1. <style name="AppTheme" parent="@style/AppThemsse">
  2.  
  3. <!-- All customizations that are NOT specific to a particular API-level can go here. -->
  4. <!-- Text styles -->
  5. <item name="android:textAppearance">@style/TextAppearance</item>
  6. <item name="android:textAppearanceInverse">@style/TextAppearance.Inverse</item>
  7. <item name="android:textAppearanceLarge">@style/TextAppearance.Large</item>
  8. <item name="android:textAppearanceMedium">@style/TextAppearance.Medium</item>
  9. <item name="android:textAppearanceSmall">@style/TextAppearance.Small</item>
  10. <item name="android:textAppearanceLargeInverse">@style/TextAppearance.Large.Inverse</item>
  11. <item name="android:textAppearanceMediumInverse">@style/TextAppearance.Medium.Inverse</item>
  12. <item name="android:textAppearanceSmallInverse">@style/TextAppearance.Small.Inverse</item>
  13. <item name="android:textAppearanceButton">@style/TextAppearance.Widget.Button</item>
  14. <item name="android:textColorPrimary">#000079</item>
  15. <item name="android:textColorSecondary">#000079</item>
  16. <item name="android:textColorTertiary">@color/tertiary_text_light</item>
  17. <item name="android:textColorPrimaryInverse">@color/primary_text_dark</item>
  18. <item name="android:textColorSecondaryInverse">@color/secondary_text_dark</item>
  19. <item name="android:textColorTertiaryInverse">@color/tertiary_text_dark</item>
  20. <item name="android:textColorPrimaryDisableOnly">@color/primary_text_light_disable_only</item>
  21. <item name="android:textColorPrimaryInverseDisableOnly">@color/primary_text_dark_disable_only</item>
  22. <item name="android:textColorPrimaryNoDisable">@color/primary_text_light_nodisable</item>
  23. <item name="android:textColorSecondaryNoDisable">@color/secondary_text_dark_nodisable</item>
  24. <item name="android:textColorPrimaryInverseNoDisable">@color/primary_text_dark_nodisable</item>
  25. <item name="android:textColorSecondaryInverseNoDisable">@color/secondary_text_dark_nodisable</item>
  26. <item name="android:textColorHint">@color/hint_foreground_light</item>
  27. <item name="android:textColorHintInverse">@color/hint_foreground_dark</item>
  28.  
  29. </style>
  30.  
  31. <style name="TextAppearance">
  32. <item name="android:textColor">?android:textColorPrimary</item>
  33. <item name="android:textColorHighlight">#FFFF9200</item>
  34. <item name="android:textColorHint">?android:textColorHint</item>
  35. <item name="android:textColorLink">#5C5CFF</item>
  36. <item name="android:textSize">16sp</item>
  37. <item name="android:textStyle">normal</item>
  38. </style>

theme修改该引用的样式

4. Theme使用

AndroidManifest.xml 中设置该Theme android:theme="**"

5. 使用View

(1)直接xml导入View

(2)先new View(这样出现了所描述的问题)

  1. PreferenceScreen mPreferenceScreen = getPreferenceManager().createPreferenceScreen(getApplicationContext());
  2. Preference mPreference = new Preference(this);
  3. mPreference.setTitle("我的应用世界");
  4. mPreference.setSummary("测试自定义Preference");
  5. mPreference.setKey("hello");
  6. mPreferenceScreen.addPreference(mPreference);

注意红色的地方,如果使用的是getApplicationContent()不知不觉中就出现无法使用theme了。

惠存!

使用了Theme但是没有效果问题的更多相关文章

  1. Material Designer的低版本兼容实现(二)—— Theme

    Theme material主题可以定义为如下形式: @android:style/Theme.Material @android:style/Theme.Material.Light @androi ...

  2. android学习笔记50——SQLiteOpenHelper、android实现系统自带样式

    SQLiteOpenHelper SQLiteOpenHelper是android提供的一个管理数据库的工具类,可用于管理数据库的创建和版本更新. 一般的用法是创建SQLiteOpenHelper的子 ...

  3. Android学习笔记--AlertDialog应用

    1. 自定义实现带图标的TextView IconTextView.java package com.evor.andtest; import android.content.Context; imp ...

  4. VSCode瞎折腾记

    搬到小机房后终于能用VSCode啦(没错以前的系统是xp) 但是这东西比Dev难搞多了qwq,简单记一下自己的DIY历程吧(不然全搞炸就凉了) 设置语言为中文 可以直接下载插件 让VSCode支持编译 ...

  5. Android中样式及主题

    Android应用程序中不可避免的需要使用的样式和主题,样式指定一般指定View的高度.字体.字体颜色.背景,Android里的样荐定义在Style.xml文件里.主题也是一种样式,只不过它是应用在整 ...

  6. C++Windows核心编程读书笔记

    转自:http://www.makaidong.com/%E5%8D%9A%E5%AE%A2%E5%9B%AD%E6%96%87/71405.shtml "C++Windows核心编程读书笔 ...

  7. 【转】《windows核心编程》读书笔记

    这篇笔记是我在读<Windows核心编程>第5版时做的记录和总结(部分章节是第4版的书),没有摘抄原句,包含了很多我个人的思考和对实现的推断,因此不少条款和Windows实际机制可能有出入 ...

  8. Activity + 基础UI

    目录 Activity + 基础UI 1. 返回键退出进入应用: 2. home键以后 3. home键退出切换字体 二:AndroidManifest配置theme改变UI效果 三:UI 报错: A ...

  9. IDEA界面太丑??尝试一下这几个风格

    >>>>>>>>>>原文地址<<<<<<<<<< >>>> ...

随机推荐

  1. nyoj 54-小明的存钱计划

    点击打开链接 小明的存钱计划 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 小明的零花钱一直都是自己管理.每个月的月初妈妈给小明300元钱,小明会预算这个月的花销,并且 ...

  2. [ZOJ 3662] Math Magic (动态规划+状态压缩)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3662 之前写过这道题,结果被康神吐槽说代码写的挫. 的确,那时候 ...

  3. 扩大View的点击范围

    扩大View的点击范围本人知道的有两种方法,在不影响界面效果的前提下: 1.在View的外面添加一个透明容器 2.就是本文要说的,代码如下 : public void addToParentArea( ...

  4. vb 取得桌面路径

    txtPath.Text = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

  5. Comparing cards

    For built-in types, there are conditional operators (<, >, ==, etc.) that compare values and d ...

  6. 修改oracle用户密码永不过期

    1.查看用户的proifle是哪个,一般是default: sql>SELECT username,PROFILE FROM dba_users; 2.查看指定概要文件(如default)的密码 ...

  7. mybatis-generator 代码自动生成工具

    今天来介绍下怎么用mybatis-gennerator插件自动生成mybatis所需要的dao.bean.mapper xml文件,这样我们可以节省一部分精力,把精力放在业务逻辑上. 之前看过很多文章 ...

  8. git大百科

    1,命令: git忽略提交文件:git rm --cache .idea/workspace.xml 因为你已经把他加到tracked file里了 用 git rm --cached java/.i ...

  9. centos custom iso

    http://www.smorgasbork.com/2012/01/04/building-a-custom-centos-6-kickstart-disc-part-1/ Create a dir ...

  10. WP8_检测列表是否滑动

    One of the UI features of lists on Windows Phone 7 is that the "scroll bars" don't really ...