读书人

定义正题

发布时间: 2012-08-22 09:50:34 作者: rapoo

定义主题

?

<?xml version="1.0" encoding="utf-8"?>

<resources>

<style name="CustomTheme">

<item name="android:windowNoTitle">true</item>

<item name="windowFrame">@drawable/screen_frame</item>

<item name="windowBackground">@drawable/screen_background_white</item>

<item name="panelForegroundColor">#FF000000</item>

<item name="panelBackgroundColor">#FFFFFFFF</item>

<item name="panelTextColor">?panelForegroundColor</item>

<item name="panelTextSize">14</item>

<item name="menuItemTextColor">?panelTextColor</item>

<item name="menuItemTextSize">?panelTextSize</item>

</style>

</resources>



注意:我们用了@符号和?符号来应用资源。@符号表明了我们应用的资源是前边定义过的(或者在前一个项目中或者在Android 框架中)。问号?表明了我们引用的资源的值在当前的主题当中定义过。通过引用在<item>里边定义的名字可以做到(panelTextColor 用的颜色和panelForegroundColor中定义的一样)。该技巧只能用在XML资源当中。

代码中应用主题:……setTheme(android.R.style.Theme_Light);setContentView(R.layout.linear_layout_3);……


读书人网 >移动开发

热点推荐