Android系统自带样式(android:theme)解析
做Android开发时经常会修改系统默认的主题样式,在android的sdk安装目录data\res\values\themes.xml 下是系统定义好的主题,可以直接使用
下面说一些常用的主题样式:
android:theme="@android:style/Theme.Dialog" : Activity显示为对话框模式
android:theme="@android:style/Theme.NoTitleBar" : 不显示应用程序标题栏
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" : 不显示应用程序标题栏,并全屏
android:theme="@android:style/Theme.Black" : 背景黑色
android:theme="@android:style/Theme.Black.NoTitleBar" : 黑色背景并无标题栏
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" : 黑色背景,无标题栏,全屏
android:theme="@android:style/Theme.Light ": 背景为白色
android:theme="@android:style/Theme.Light.NoTitleBar" : 白色背景并无标题栏
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" : 白色背景,无标题栏,全屏
android:theme="@android:style/Theme.Wallpaper" : 用系统桌面为应用程序背景
android:theme="@android:style/Theme.Wallpaper.NoTitleBar" : 用系统桌面为应用程序背景,且无标题栏
android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen" : 用系统桌面为应用程序背景,无标题栏,全屏
android:theme="@android:style/Theme.Translucent : 透明背景
android:theme="@android:style/Theme.Translucent.NoTitleBar" : 透明背景并无标题
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" : 透明背景并无标题,全屏
android:theme="@android:style/Theme.Panel ": 面板风格显示
android:theme="@android:style/Theme.Light.Panel" : 平板风格显示
如果整个工程用一个主题就在application标签中定义。
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name"android:theme="@style/AppTheme">
如果是每个activety用不同主题,则在不同的activity标签中引用,例如
<activity android:name="com.example.activity.MainActivity" android:label="@string/app_name" android:theme="@android:style/Theme.Light.NoTitleBar">
当然理论要多和实际联系,下面说个实际应用,大多数Android系统默认Activity间的动画切换效果为,右边滑入,左边滑出。有时候我们的需求可能是要求所有Activity的切换为淡入淡出的效果,这时候就可能需要改变一下默认的切换风格。
下面开始实现:
- 首先在res文件夹下建立anim文件夹,然后在里面建立fade_in.xml和fade_out.xml两个动画资源
fade_in.xml
<?xmlversion="1.0"encoding="utf-8"?> <alphaxmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromAlpha="0.0" android:interpolator="@android:anim/accelerate_interpolator" android:toAlpha="1.0"/>fade_out.xml
<?xmlversion="1.0"encoding="utf-8"?>
<alphaxmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="0.0"/>
- 然后在values文件夹下的styles.xml中的resources标签内写:
<stylename="fade"parent="@android:style/Animation.Activity">
<itemname="android:activityOpenEnterAnimation">@anim/fade_in</item>
<itemname="android:activityOpenExitAnimation">@anim/fade_out</item>
<itemname="android:activityCloseEnterAnimation">@anim/fade_in</item>
<itemname="android:activityCloseExitAnimation">@anim/fade_out</item>
</style>
<stylename="Anim_fade"parent="android:Theme.NoTitleBar">
<itemname="android:windowAnimationStyle">@style/fade</item>
</style>
- 最后修改AndroidManifest.xml
<activity android:name="com.example.activity.CustomAnimActivity" android:label="@string/app_name" android:theme="@style/Anim_fade"/>
MainActivity.java类如下:
publicclassMainActivityextendsActivity{ @Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Buttonbtn=(Button)findViewById(R.id.button);
btn.setOnClickListener(newOnClickListener(){
@Override publicvoidonClick(Viewarg0){ Intentintent=newIntent(MainActivity.this, CustomAnimActivity.class); startActivity(intent); } }); }
效果如下:
源代码
参考文章:
http://blog.sina.com.cn/s/blog_bfe1efad0101ado8.html http://38275.blog.51cto.com/28275/710003 http://387424-student-sina-com.iteye.com/blog/1746704
http://blog.csdn.net/lmj623565791/article/details/22990643
更多相关文章
- ANDROID 单元测试
- 自定义seekbar
- android button 正常状态,按下状态
- android selector 背景选择器的使用, button (未点击,点击,选中保持
- android button 正常状态,按下状态
- 1、一、Introduction(入门): 0、Introduction to Android(引进到
- ch028 Android(安卓)断点续传
- ch016 Android(安卓)自定义对话框.
- ch031 Android(安卓)AsyncTask