Android中theme的用法
2010-12-24 14:49
369 查看
Theme在android的可以采用如下两种办法 :
一,在AndroidManifest.xml文件中,对Activity元素添加andorid:theme属性 ,如文中红色部分。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mike.lei.shen"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TestActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
二 ,在java代码中设置 Theme。
package mike.lei.shen;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TextView;
public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
this.setTheme(android.R.style.Theme_Light);
super.onCreate(savedInstanceState);
//this.setTheme(android.R.style.Theme_Light);
setContentView(R.layout.main);
TextView tv = (TextView)findViewById(R.id.TxtHello);
tv.setText("screen with Light theme!");
}
}
注意,红色代码的位置很重要,API中建议在setContentView之前调用,但在android2.3中是没有用的(其他平台可能也有这个问题)
必须在 super.onCreate(savedInstanceState)之前调用。
两种方法的调用效果图
:
一,在AndroidManifest.xml文件中,对Activity元素添加andorid:theme属性 ,如文中红色部分。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mike.lei.shen"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TestActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
二 ,在java代码中设置 Theme。
package mike.lei.shen;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TextView;
public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
this.setTheme(android.R.style.Theme_Light);
super.onCreate(savedInstanceState);
//this.setTheme(android.R.style.Theme_Light);
setContentView(R.layout.main);
TextView tv = (TextView)findViewById(R.id.TxtHello);
tv.setText("screen with Light theme!");
}
}
注意,红色代码的位置很重要,API中建议在setContentView之前调用,但在android2.3中是没有用的(其他平台可能也有这个问题)
必须在 super.onCreate(savedInstanceState)之前调用。
两种方法的调用效果图
:
相关文章推荐
- android的theme的用法
- Android 下style和theme的用法
- Android中的style和theme的用法
- Android入门之Style与Theme用法实例解析
- Android Style、Theme基本用法
- Android中theme的用法
- Android:interpolator用法
- Android之Adapter用法总结
- Android 自定义属性用法详解
- Android中的ContentValues用法
- android HttpURLConnection用法详解
- MPAndroidChart API用法
- C#开发android之alertdialog用法
- Android 中SQList用法详解(增删查改)
- Android Volley完全解析(一),初识Volley的基本用法
- Android开发:LayoutParams的用法
- Android事件总线EventBus3.0用法全解析
- Android ViewPager用法小结
- android:theme 与 setTheme()设置透明效果并不同
- Android MimeType的用法和几种类型