您的位置:首页 > 编程语言 > Java开发

个人笔记之style

2016-01-03 14:12 483 查看
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
 
<!-- 去掉标题栏 -->
<item name="android:windowNoTitle">true</item>
</style>
 
<!-- 在样式文件中 可以抽取布局文件中相同的代码 -->
<style name="btn_next">
<item name="android:onClick">next</item>
<item name="android:background">@drawable/button</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_alignParentBottom">true</item>
<item name="android:layout_alignParentRight">true</item>
<item name="android:drawableRight">@drawable/next</item>
<item name="android:text">下一步</item>
<item name="android:textColor">#000000</item>
</style>
 
<style name="btn_pre">
<item name="android:onClick">pre</item>
<item name="android:background">@drawable/button</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_alignParentBottom">true</item>
<item name="android:layout_alignParentLeft">true</item>
<item name="android:drawableLeft">@drawable/previous</item>
<item name="android:text">上一步</item>
<item name="android:textColor">#000000</item>
</style>


1.以上是style的例子。将布局文件xml中相同的代码抽取出来统一的放到style.xml中!在布局文件中直接调用style

<Button
style="@style/btn_pre"
/>
<Button
style="@style/btn_next"/>


2.如果在xml布局中需要更改style中的属性,只需要覆盖style中的属性即可!如下:更改了style中的背景和text文字,直接覆盖即可!

<Button
style="@style/btn_pre"
/>
<Button
style="@style/btn_next"
android:text="设置完成"
android:drawableRight="@null"/>


3.style的继承

    1).加上parent

     

<style name="TextViewStyle2" parent="@style/TextViewStyle1">
<item name="android:layout_width">400dp</item>
  </style>


2).加点

       

<style name="TextViewStyle1.test">
<item name="android:layout_width">800dp</item>
   </style>


  3).还可以多继承:

    

<style name="TextViewStyle1.test.test">
<item name="android:layout_width">1200dp</item>
</style>


4.theme:影响整个个程序的显示:

<pre name="code" class="html"> 
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
<strong><item name="android:textSize">60sp</item>
<item name="android:typeface">monospace</item></strong>
</style>  


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  myeclipse