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

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

1. xml中使用样式。

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

2.View中使用到xml

  setContentView(xml)

3. 定义Theme

    <style name="AppTheme" parent="@style/AppThemsse">

        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
<!-- Text styles -->
<item name="android:textAppearance">@style/TextAppearance</item>
<item name="android:textAppearanceInverse">@style/TextAppearance.Inverse</item>
<item name="android:textAppearanceLarge">@style/TextAppearance.Large</item>
<item name="android:textAppearanceMedium">@style/TextAppearance.Medium</item>
<item name="android:textAppearanceSmall">@style/TextAppearance.Small</item>
<item name="android:textAppearanceLargeInverse">@style/TextAppearance.Large.Inverse</item>
<item name="android:textAppearanceMediumInverse">@style/TextAppearance.Medium.Inverse</item>
<item name="android:textAppearanceSmallInverse">@style/TextAppearance.Small.Inverse</item>
<item name="android:textAppearanceButton">@style/TextAppearance.Widget.Button</item>
<item name="android:textColorPrimary">#000079</item>
<item name="android:textColorSecondary">#000079</item>
<item name="android:textColorTertiary">@color/tertiary_text_light</item>
<item name="android:textColorPrimaryInverse">@color/primary_text_dark</item>
<item name="android:textColorSecondaryInverse">@color/secondary_text_dark</item>
<item name="android:textColorTertiaryInverse">@color/tertiary_text_dark</item>
<item name="android:textColorPrimaryDisableOnly">@color/primary_text_light_disable_only</item>
<item name="android:textColorPrimaryInverseDisableOnly">@color/primary_text_dark_disable_only</item>
<item name="android:textColorPrimaryNoDisable">@color/primary_text_light_nodisable</item>
<item name="android:textColorSecondaryNoDisable">@color/secondary_text_dark_nodisable</item>
<item name="android:textColorPrimaryInverseNoDisable">@color/primary_text_dark_nodisable</item>
<item name="android:textColorSecondaryInverseNoDisable">@color/secondary_text_dark_nodisable</item>
<item name="android:textColorHint">@color/hint_foreground_light</item>
<item name="android:textColorHintInverse">@color/hint_foreground_dark</item> </style> <style name="TextAppearance">
<item name="android:textColor">?android:textColorPrimary</item>
<item name="android:textColorHighlight">#FFFF9200</item>
<item name="android:textColorHint">?android:textColorHint</item>
<item name="android:textColorLink">#5C5CFF</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">normal</item>
</style>

theme修改该引用的样式

4. Theme使用

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

5. 使用View

(1)直接xml导入View

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

        PreferenceScreen mPreferenceScreen = getPreferenceManager().createPreferenceScreen(getApplicationContext());
Preference mPreference = new Preference(this);
mPreference.setTitle("我的应用世界");
mPreference.setSummary("测试自定义Preference");
mPreference.setKey("hello");
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. ubuntu英文乱码解决

     ubuntu英文乱码: vi /etc/default/locale LANG="en_US.UTF-8" LANGUAGE="en_US:en" 配置更 ...

  2. Spark是一种分布式的计算方案

    Spark的安装基于HDFS,所以我们要设置hadoop的配置文件,所以spark的存储不是其主要的功能点,而spark作为分布式生态中的角色是一种计算模式(其他 的计算 模式,比如MR,Storm, ...

  3. 菜鸟-手把手教你把Acegi应用到实际项目中(7)-缓存用户信息

    首先讲讲EhCache.在默认情况下,即在用户未提供自身配置文件ehcache.xml或ehcache-failsafe.xml时,EhCache会依据其自身Jar存档包含的ehcache-fails ...

  4. centos6.5网络配置问题:ping不通

    遇到的问题:win7网卡ping不通 win7中的VMnet8信息 centos6.5设置: /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 ...

  5. 自动以读写方式挂载ntfs-黑苹果之路

    在mac下ntfs分区总是以只读方式挂载,双操作系统,尤其有些时候需要用u盘,需要手工umount再mount,很麻烦,找了一些资料,通过修改/etc/fstab文件无效,要么就是使用第三方软件,不合 ...

  6. regulator

    http://blog.sina.com.cn/s/blog_5e99b41e0101a3ng.html http://blog.sina.com.cn/s/blog_694348b00100n3ip ...

  7. Sqoop2入门之导入关系型数据库数据到HDFS上

    需求:将hive数据库中的TBLS表导出到HDFS之上: $SQOOP2_HOME/bin/sqoop.sh client sqoop:> set server --host hadoop000 ...

  8. cocos2d3.0跑酷代码讲解和源码

    最近在网上看到一个跑酷代码的例子,写的很不错,连接如下 http://www.waitingfy.com/archives/783 现在我把他精简了一下,去除了一些比较简单的特效,着重保留了主角的跳跃 ...

  9. linux tar 命令 --致力于“一眼看懂,随手就用”的随笔

    基本玩法: 压缩: tar -czf txt.tar.gz *.txt // 将当前目录下的所有txt文件,创建一个tar包,并用gzip算法,压缩成txt.tar.gz 文件 解压: tar -xz ...

  10. 华为OJ平台——统计字符串中的大写字母

    题目描述: 统计字符串中的大写字母的个数 输入: 一行字符串 输出: 字符串中大写字母的个数(当空串时输出0) 思路: 这一题很简单,直接判断字符串中的每一个字符即可,唯一要注意的一点是输入的字符串可 ...