前面提到了主题Theme这个话题。我们先看看如何将整个Application应用主题。
在AndroidManifest.xml文件中有个application的子节点,可以添加我们的style应用整个程序。
- <application android:icon="@drawable/icon"
- android:label="@string/app_name"
- android:theme="@style/buttonstyle"
- >
当然一个程序可能有多个Activity,我们可以分别为他们自定主题。下面的列子让我们的程序透明起来。
- public class StyleTestActivity extends Activity implements OnClickListener{
- /** Called when the activity is first created. */
- Button button ;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- button = (Button)findViewById(R.id.button);
- button.setOnClickListener(this);
- }
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- Toast toast = Toast.makeText(getApplicationContext(), "hello android", Toast.LENGTH_SHORT);
- toast.show();
- }
- }
下面内容在res/velus/style.xml中
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <color name="transparent_background">#44004400</color>
- <style name="transparent">
- <item name="android:windowBackground">@color/transparent_background</item>
- <item name="android:windowNoTitle">true</item>
- <item name="android:windowIsTranslucent">true</item>
- <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>
- </style>
- </resources>
在AndroidManifest.xml中指定主题:
-
- <activity android:name=".StyleTestActivity"
- android:label="@string/app_name"
布局mian.xml就自己写吧……
