您的位置:首页 > 移动开发 > Android开发

Android学习笔记之Theme主题的修改设置

2015-01-16 16:20 459 查看
(1)布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<!-- 普通的样式使用方法 -->

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="31dp"
android:text="@string/hello_world" />

<!-- 自定义的样式使用方法 -->

<TextView
android:id="@+id/textView1"
style="@style/CodeFont.RED.BIG"
android:text="@string/hello_world" />

<Button
android:id="@+id/button1"
style="@style/buttonStyle"
android:layout_alignLeft="@+id/textView2"
android:layout_centerVertical="true"
android:text="Button"
android:textColor="@color/textColor" />

</RelativeLayout>

(2)在values中新建xml文件
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:typeface">monospace</item>
</style>

<style name="CodeFont.RED">
<item name="android:textColor">#00FF00</item>
</style>

<style name="CodeFont.RED.BIG">
<item name="android:textSize">20sp</item>
</style>

<style name="buttonStyle">
<item name="android:textColor">#00FF00</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">48dp</item>
<item name="android:layout_marginLeft">148dp</item>
</style>

<color name="textColor">#ACBDEC</color>

<!-- 自定义主题 需要在清单文件中修改Android默认的主题 -->
<color name="custom_theme_color">#b0b0ff</color>

<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowBackground">@color/custom_theme_color</item>
<item name="android:colorBackground">@color/custom_theme_color</item>
</style>

</resources>

(3)如果要修改Android默认的主题需要在清单文件中修改,下图圈出的位置就是需要修改的地方



(4)其他问阿金都可以默认无需修改!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: