你好,游客 登录 注册 搜索
背景:
阅读新闻

Android :Style的使用

[日期:2011-08-06] 来源:Linux社区  作者:tsiannian [字体:大 中 小]

前面提到了主题Theme这个话题。我们先看看如何将整个Application应用主题。

在AndroidManifest.xml文件中有个application的子节点,可以添加我们的style应用整个程序。

  1. <application android:icon="@drawable/icon"   
  2.              android:label="@string/app_name"  
  3.              android:theme="@style/buttonstyle"  
  4.              >  

当然一个程序可能有多个Activity,我们可以分别为他们自定主题。下面的列子让我们的程序透明起来。

  1. public class StyleTestActivity extends Activity implements OnClickListener{  
  2.     /** Called when the activity is first created. */  
  3.     Button button ;  
  4.     @Override  
  5.     public void onCreate(Bundle savedInstanceState) {  
  6.         super.onCreate(savedInstanceState);  
  7.         setContentView(R.layout.main);  
  8.         button = (Button)findViewById(R.id.button);  
  9.         button.setOnClickListener(this);  
  10.     }  
  11.     @Override  
  12.     public void onClick(View v) {  
  13.         // TODO Auto-generated method stub   
  14.         Toast toast = Toast.makeText(getApplicationContext(), "hello android", Toast.LENGTH_SHORT);  
  15.         toast.show();  
  16.     }  
  17. }  

下面内容在res/velus/style.xml中

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <color name="transparent_background">#44004400</color>  
  4.     <style name="transparent">  
  5.        <item name="android:windowBackground">@color/transparent_background</item>  
  6.        <item name="android:windowNoTitle">true</item>  
  7.        <item name="android:windowIsTranslucent">true</item>  
  8.        <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>  
  9.      </style>  
  10. </resources>  

在AndroidManifest.xml中指定主题:

  1. <activity android:name=".StyleTestActivity"  
  •                   android:label="@string/app_name"  
  •                   android:theme="@style/transparent">  
  •             <intent-filter>  
  •                 <action android:name="android.intent.action.MAIN" />  
  •                 <category android:name="android.intent.category.LAUNCHER" />  
  •             </intent-filter>  
  •         </activity>  
  • 布局mian.xml就自己写吧……

    linux
    相关资讯       Android教程 
    本文评论   查看全部评论 (0)
    表情: 表情 姓名: 字数

           

    评论声明
    • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
    • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
    • 本站管理人员有权保留或删除其管辖留言中的任意内容
    • 本站有权在网站内转载或引用您的评论
    • 参与本评论即表明您已经阅读并接受上述条款