您的位置:首页 > 移动开发 > Android开发

android如何自定义style

2016-05-02 17:23 423 查看
1、在resource里自定义style

2、在控件属性中使用自定义style

代码:

1、

<resources xmlns:android="http://schemas.android.com/apk/res/android">
//style可以通过指定parent属性继承
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>

//定义style名
<style name="testStyle">
//定义style的属性
<item name="android:textSize">30px</item>
<item name="android:textColor">#1110CC</item>
<item name="android:width">150dip</item>
<item name="android:height">150dip</item>
</style>

</resources>


使用示例:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<TextView
<!-- 使用自定义style -->
style="@style/testStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />

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