当前位置: 移动技术网 > IT编程>移动开发>Android > Android自定义Style实现方法

Android自定义Style实现方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

海霞树小说网,青年宫影城,80特区交友

styles.xml如下:
[html]

复制代码 代码如下:

<resources xmlns:android="http://schemas.android.com/apk/res/android"> 
    <style name="appbasetheme" parent="android:theme.light"> 
    </style> 
    <style name="apptheme" parent="appbasetheme"> 
    </style> 

     <style name="teststyle">  
        <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> 
 

main.xml如下:
[html] 

复制代码 代码如下:

<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/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> 

mainactivity如下:
[java]

复制代码 代码如下:

package com.cn; 
import android.os.bundle; 
import android.app.activity; 
/**
 * demo示例:
 * 为控件设置自定义的style
 * 步骤:
 * 1 在styles.xml文件中自定义一个style
 *   在该style中可以预设各种参数.如文字大小,颜色
 *   宽,高等等属性
 * 2 在布局文件中为控件设置style属性,如:style="@style/teststyle"
 */ 
public class mainactivity extends activity { 
    @override  www.jb51.net
    protected void oncreate(bundle savedinstancestate) { 
        super.oncreate(savedinstancestate); 
        setcontentview(r.layout.main); 
    } 


如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网