android自定义theme
来源:互联网 发布:女装免费加盟开淘宝店 编辑:程序博客网 时间:2024/06/05 19:30
转载自:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2012/1009/422.html
android中可以自定义主题和风格。首先,style和theme都是资源,android提供了很多这样的默认资源。风格,也就是style,我们可以将一些统一的属性拿出来,比方说,长,宽,字体大小,字体颜色等等。可以在res/values目录下新建一个styles.xml的文件,在这个文件里面有resource根节点,在根节点里面添加item项,item项的名字就是属性的名字,item项的值就是属性的值,如下所示:
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<resources>
<style name=
"MyText"
parent=
"@android:style/TextAppearance"
>
<item name=
"android:textColor"
>
#987456</item>
<item name=
"android:textSize"
>24sp</item>
</style>
</resources>
style中有一个父类属性parent, 这个属性是说明当前的这个style是继承自那个style的,当然这个style的属性值中都包含那个属性中的,你也可以修改继承到的属性的值,好了,style完成了,我们可以测试一下效果了,先写一个布局文件,比如说一个TextView什么的,可以用到这个style的。这里我就写一个EditText吧。下面是布局文件:
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<EditText
android:id=
"@+id/myEditText"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
style=
"@style/MyText"
android:text=
"测试一下下"
/>
</LinearLayout>
说完了style,下面就说说Theme,Theme跟style差不多,但是Theme是应用在Application或者Activity里面的,而Style是应用在某一个View里面的,还是有区别的,好了,废话不多说,还是看代码吧。下面的是style文件:
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<resources>
<style name=
"MyText"
parent=
"@android:style/TextAppearance"
>
<item name=
"android:textColor"
>
#987456</item>
<item name=
"android:textSize"
>24sp</item>
</style>
<style parent=
"@android:style/Theme"
name=
"CustomTheme"
>
<item name=
"android:windowNoTitle"
>
true
</item>
<item name=
"android:windowFrame"
>@drawable/icon</item>
<item name=
"android:windowBackground"
>?android:windowFrame</item>
</style>
</resources>
可以看到这里写了一个继承自系统默认的Theme的主题,里面有3个属性,这里强调一下第三个属性的值的问题,这里打个问号,然后加前面的一个item的名字表示引用的是那个名字的值,也就是那个名字对应的图片。
然后我们在Manifest.xml里面的Application里面加一个Theme的属性,这个属性对应的就是我们上面写的Theme。
<application android:icon=
"@drawable/icon"
android:label=
"@string/app_name"
android:theme=
"@style/CustomTheme"
>
<activity android:name=
".TestStyle"
android:label=
"@string/app_name"
>
<intent-filter>
<action android:name=
"android.intent.action.MAIN"
/>
<category android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
当然也可以在代码中设置主题:
package com.test.shang;
import android.app.Activity;
import android.os.Bundle;
public class TestStyle extends Activity {
@Override
protected void onCreate (Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setTheme(R.style.CustomTheme);
setContentView(R.layout.test_style);
}
}
- android 关于自定义Theme
- Android自定义Theme&style
- Android 自定义theme
- android自定义theme尝试
- android自定义theme
- android自定义theme的使用
- Android系统自定义Android Lollipop Theme
- Android中自定义主题风格theme.xml
- Android之自定义式Style与Theme
- android Button Theme 自定义小技巧
- android 添加自定义theme和style
- Android 自定义Style、Theme以及继承
- 【Android】自定义Style或Theme及自定义ActionBar
- Android中自定义样式(style)与主题(theme)
- android通过自定义theme个性化标题栏并且文字居中
- Android UI中的自定义style和theme以及AlertDialog
- Android修炼之道——Theme自定义ActionBar
- android 自定义activity的窗口大小(theme运用)
- fips2
- 安装nginx实录
- android系统自带的主题
- nginx平滑升级
- go语音之select
- android自定义theme
- 用 goto + if 模拟 循环
- eclipse集成Android NDK说明
- MySQL的configure参数详解
- uva10310(SuperSale)
- Linux文件解压缩
- HDU 1298 T9 // 字典树,枚举,dfs
- 使用NSURLCache让本地数据来代替远程UIWebView请求
- Linux文件操作