在前学做web开发时。写jsp页面时,总会用到css样式来渲染页面。这样页面才好看。比方说:
<style>
.style{color:red;font-size:18px;}
</style>
然后在页面上引用。
<div class="style">XXXXX</div>
学习android同样也需要定义一样样式用来渲染页面。
首先:我们在res/values/styles.xml
格式如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>
然后我们定义样式,最终实现如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--定义一个为单一控制的样式 name的值要全局为一 -->
<style name="text">
<item name="android:textColor">#0000cc</item>
<item name="android:textSize">15sp</item>
</style>
<!-- 可以使用parent 继承一个样子 格式如下 -->
<style name="extendText" parent="@style/text">
<item name="android:textColor">#FFF000</item>
</style>
<!--定义一个主题 -->
<style name="textTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">?android:windowNoTitle</item>
</style>
</resources>
然后我们在loyout/main.xml中调用样式.
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
style="@style/extendText"
/>
在AndroidManifest.xml 中调用主题:
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".StyleDemoActivity" android:label="@string/app_name"
android:theme="@style/textTheme"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
上图: