分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.youkuaiyun.com/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
在Android里面,样式的概念跟网页中CSS样式表的概念相似,并且样式之间也可以继承
下面为两个文本框定义样式,创建一个my_style.xml文件放在res/values文件夹下,注意样式文件的根元素是resouces
<?xml version="1.0" encoding="utf-8"?><resources> <!-- 定义一个样式,指定字体大小,字体颜色 --> <style name="style1"> <item name="android:textSize">20sp</item> <item name="android:textColor">#00d</item> </style> <!-- 定义一个样式,继承前一个颜色 --> <style name="style2" parent="@style/style1"> <item name="android:background">#ee6</item> <item name="android:padding">8dp</item> <!-- 覆盖父样式中指定的属性 --> <item name="android:textColor">#000</item> </style></resources>
上面定义了两个样式,并且第二个样式还继承和覆盖了第一样式,下面在主界面xml中引用样式
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <EditText android:id="@+id/editText1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/style1" style="@style/style1" android:ems="10" > <requestFocus /> </EditText> <EditText android:id="@+id/editText2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/style2" style="@style/style2" android:ems="10" /></LinearLayout>
在valuse方位夹下的strings里定义两个文本框显示的文字
<?xml version="1.0" encoding="utf-8"?><resources> <string name="app_name">StyleResTest</string> <string name="style1">样式1的格式</string> <string name="style2">样式2的格式</string></resources>
运行效果如下
上图的两个文本框已经使用了上面定义好的样式,感觉和做网页一样
给我老师的人工智能教程打call!http://blog.youkuaiyun.com/jiangjunshow
