Android常见主题

Android常见主题,第1张

android:theme="@android:style/Theme.Dialog" //Activity显示为对话框模式

android:theme="@android:style/Theme.NoTitleBar" //不显示应用程序标题栏

android:theme="@android:style/Theme.NoTitleBar.Fullscreen" //不显示应用程序标题栏,并全屏

android:theme="Theme.Light " //背景为白色

android:theme="Theme.Light.NoTitleBar" //白色背景并无标题栏

android:theme="Theme.Light.NoTitleBar.Fullscreen" //白色背景,无标题栏,全屏

android:theme="Theme.Black" //背景黑色

android:theme="Theme.Black.NoTitleBar" //黑色背景并无标题栏

android:theme="Theme.Black.NoTitleBar.Fullscreen" //黑色背景,无标题栏,全屏

android:theme="Theme.Wallpaper" //用系统桌面为应用程序背景

android:theme="Theme.Wallpaper.NoTitleBar" //用系统桌面为应用程序背景,且无标题栏

android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" //用系统桌面为应用程序背景,无标题栏,全屏

android:theme="Theme.Translucent" //透明背景

android:theme="Theme.Translucent.NoTitleBar" //透明背景并无标题

android:theme="Theme.Translucent.NoTitleBar.Fullscreen" //透明背景并无标题,全屏

android:theme="Theme.Panel " //面板风格显示

android:theme="Theme.Light.Panel" //平板风格显示

Android 应用程序中使用自定义主题的方法:

1、新建一个项目 Lesson32_StyleAndTheme。

2、拷贝下面三张 Nine-Patch PNG图片到res/drawable目录下:

3、在按钮的同目录下建立一个文件btn_custom.xml,把上述3张图片整合成一个按钮背景文件,让三张图片成为不同状态下的按钮表现效果。具体写法如下:

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

<selector xmlns:android="http://schemas.android.com/apk/res/android">  

<item android:drawable="@drawable/btn_red" android:state_enabled="false">

<item android:drawable="@drawable/btn_orange" android:state_enabled="true" android:state_pressed="true">

<item android:drawable="@drawable/btn_orange" android:state_enabled="true" android:state_focused="true">

<item android:drawable="@drawable/btn_black" android:state_enabled="true">

</item></item></item></item></selector>

4、在res/values目录下定义style.xml文件,内容如下:

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

<resources>

<style name="BasicButtonStyle" parent="@android:style/Widget.Button">

<item name="android:gravity">center_vertical|center_horizontal</item>

<item name="android:textColor">#ffffffff</item>

<item name="android:shadowColor">#ff000000</item>

<item name="android:shadowDx">0</item>

<item name="android:shadowDy">-1</item>

<item name="android:shadowRadius">0.2</item>

<item name="android:textSize">16dip</item>

<item name="android:textStyle">bold</item>

<item name="android:background">@drawable/btn_custom</item>

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

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

</style>

<style name="BigTextStyle">

<item name="android:layout_margin">5dp</item>

<item name="android:textColor">#ff9900</item>

<item name="android:textSize">25sp</item>

</style>

<style name="BasicButtonStyle.BigTextStyle">

<item name="android:textSize">25sp</item>

</style>

</resources>

5、在res/layout/目录下定义main.xml文件,内容如下:

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

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical">

<textview android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="张信哲的热搜歌曲">

<button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="爱如潮水 " android:id="@+id/Button01">

</button>

</textview></linearlayout>

6、在res/values目录下定义theme.xml文件:

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

<resources>        

<style name="BasicButtonTheme">

<item name="android:buttonStyle">@style/basicbuttonstyle</item>

<item name="android:windowBackground">@android:color/transparent</item>  

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

</style>

</resources>

7、在AndroidManifest.xml中给整个应用程序设置主题:

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android.basic.lesson32" android:versioncode="1" android:versionname="1.0">  

<application android:theme="@style/BasicButtonTheme" android:label="@string/app_name" android:icon="@drawable/icon">

<activity android:label="@string/app_name" android:name=".MainStyleAndTheme">

<intent -filter="">

<action android:name="android.intent.action.MAIN">

<category android:name="android.intent.category.LAUNCHER">

</category></action></intent>

</activity>

</application>

<uses -sdk="" android:minsdkversion="8">

</uses></manifest>

8、程序的最终运行效果图如下:


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/11893384.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存