テーマ

23519 ワード

一、テーマとスタイルには何の違いもありません.主に注目点が違います.テーマは主にactivityに注目し、styleは主にコントロールに注目する.テーマの配置はリストファイルのactivityラベルの中で配置して、具体的にコードを見ます
二、コード実装
1、sytles.xmlファイル
 1 <resources xmlns:android="http://schemas.android.com/apk/res/android">
 2 
 3     
 7     <style name="AppBaseTheme" parent="android:Theme.Light">
 8         
13     style>
14 
15     
16     <style name="AppTheme" parent="AppBaseTheme">
17         
18     style>
19     <style name="mytheme">
20         <item name="android:background">#ff0000item>
21     style>
22      <style name="myblue">
23         <item name="android:windowNoTitle">trueitem>
24         <item name="android:windowBackground">@drawable/mmitem>
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 }

注意:true説明にタイトルバーはありません
@drawable/mm説明背景はアプリケーション全体のウィンドウです
転載先:https://www.cnblogs.com/zhongyinghe/p/5361713.html