主题
一、主题和样式是没有什么区别的,主要是它们关注点不同;主题主要关注activity,而style主要关注控件;而主题的配置在清单文件的activity标签中进行配置,具体看代码
二、代码实现
1、sytles.xml文件
1 <resources xmlns:android="http://schemas.android.com/apk/res/android"> 2 3 <!-- 4 Base application theme, dependent on API level. This theme is replaced 5 by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 6 --> 7 <style name="AppBaseTheme" parent="android:Theme.Light"> 8 <!-- 9 Theme customizations available in newer API levels can go in 10 res/values-vXX/styles.xml, while customizations related to 11 backward-compatibility can go here. 12 --> 13 </style> 14 15 <!-- Application theme. --> 16 <style name="AppTheme" parent="AppBaseTheme"> 17 <!-- All customizations that are NOT specific to a particular API-level can go here. --> 18 </style> 19 <style name="mytheme"> 20 <item name="android:background">#ff0000</item> 21 </style> 22 <style name="myblue"> 23 <item name="android:windowNoTitle">true</item> 24 <item name="android:windowBackground">@drawable/mm</item> 25 </style> 26 </resources>
2、清单文件
1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.example.mytheme" 4 android:versionCode="1" 5 android:versionName="1.0" > 6 7 <uses-sdk 8 android:minSdkVersion="8" 9 android:targetSdkVersion="19" /> 10 11 <application 12 android:allowBackup="true" 13 android:icon="@drawable/ic_launcher" 14 android:label="@string/app_name" 15 android:theme="@style/mytheme"> 16 <activity 17 18 android:name="com.example.mytheme.MainActivity" 19 android:label="@string/app_name" > 20 <intent-filter> 21 <action android:name="android.intent.action.MAIN" /> 22 23 <category android:name="android.intent.category.LAUNCHER" /> 24 </intent-filter> 25 </activity> 26 <activity 27 android:name="com.example.mytheme.Activity02" 28 android:theme="@style/myblue"> 29 30 </activity> 31 <activity 32 android:name="com.example.mytheme.Activity03"> 33 34 </activity> 35 </application> 36 37 </manifest>
3、视图
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" 6 tools:context=".MainActivity" > 7 8 <Button 9 android:onClick="start02" 10 android:layout_width="wrap_content" 11 android:layout_height="wrap_content" 12 android:text="开启02" /> 13 <Button 14 android:onClick="start03" 15 android:layout_width="wrap_content" 16 android:layout_height="wrap_content" 17 android:text="开启03" /> 18 19 </LinearLayout>
4、主界面代码
1 package com.example.mytheme; 2 3 import android.os.Bundle; 4 import android.app.Activity; 5 import android.content.Intent; 6 import android.view.Menu; 7 import android.view.View; 8 9 public class MainActivity extends Activity { 10 11 @Override 12 protected void onCreate(Bundle savedInstanceState) { 13 super.onCreate(savedInstanceState); 14 setContentView(R.layout.activity_main); 15 } 16 17 public void start02(View view){ 18 Intent intent = new Intent(this, Activity02.class); 19 startActivity(intent); 20 } 21 22 public void start03(View view){ 23 Intent intent = new Intent(this, Activity03.class); 24 startActivity(intent); 25 } 26 27 }
5、其他界面代码
1 package com.example.mytheme; 2 3 import android.os.Bundle; 4 import android.app.Activity; 5 import android.view.Menu; 6 import android.widget.TextView; 7 8 public class Activity02 extends Activity { 9 10 @Override 11 protected void onCreate(Bundle savedInstanceState) { 12 super.onCreate(savedInstanceState); 13 TextView tv = new TextView(this); 14 tv.setText("我是界面二"); 15 16 setContentView(tv); 17 } 18 19 @Override 20 public boolean onCreateOptionsMenu(Menu menu) { 21 // Inflate the menu; this adds items to the action bar if it is present. 22 getMenuInflater().inflate(R.menu.main, menu); 23 return true; 24 } 25 26 }
1 package com.example.mytheme; 2 3 import android.os.Bundle; 4 import android.app.Activity; 5 import android.view.Menu; 6 import android.widget.TextView; 7 8 public class Activity03 extends Activity { 9 10 @Override 11 protected void onCreate(Bundle savedInstanceState) { 12 super.onCreate(savedInstanceState); 13 TextView tv = new TextView(this); 14 tv.setText("我是界面三"); 15 16 setContentView(tv); 17 } 18 19 @Override 20 public boolean onCreateOptionsMenu(Menu menu) { 21 // Inflate the menu; this adds items to the action bar if it is present. 22 getMenuInflater().inflate(R.menu.main, menu); 23 return true; 24 } 25 26 }
注意:<item name="android:windowNoTitle">true</item>说明没有标题栏
<item name="android:windowBackground">@drawable/mm</item>说明背景是整个应用程序的窗口

浙公网安备 33010602011771号