爱程序网

android样式和主题(一)

来源: 阅读:

《android注册页面》博客中main.xml代码中每个组件定义的属性有重复的部分,为了避免繁琐可以把各个组件重复的属性定义到一个文件中:res/values/
style_test.xml源码:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="CodeFont" parent="@android:style/TextAppearance.Medium">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textSize">16sp</item>
  </style>
</resources>

main.xml文件做如下修改:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:stretchColumns="1"
  android:background="@drawable/bluesky"
>

<!-- 账号 -->
<TableRow>
  <TextView
    style="@style/CodeFont"
    android:text="账号:"
  />
  <EditText
    style="@style/CodeFont"
    android:hint="手机号"
    android:selectAllOnFocus="true"
  />
</TableRow>

<!-- 密码 -->
<TableRow>
  <TextView
    style="@style/CodeFont"
    android:text="密码:"
  />
  <EditText
    style="@style/CodeFont"
    android:inputType="numberPassword"
  />
</TableRow>

<!-- 生日 -->
<TableRow>
  <TextView
    style="@style/CodeFont"
    android:text="生日:"
  />
  <EditText
    style="@style/CodeFont"
    android:inputType="date"
  />
</TableRow>

<!-- 住址 -->
<TableRow>
  <TextView
    style="@style/CodeFont"
    android:text="住址:"
  />
  <EditText
    style="@style/CodeFont"
    android:inputType="textPostalAddress"
  />
</TableRow>

<!-- 电子邮箱 -->
<TableRow>
  <TextView
    style="@style/CodeFont"
    android:text="电子邮箱:"
  />
  <EditText
    style="@style/CodeFont"
    android:inputType="textEmailAddress"
  />
</TableRow>

<!-- 注册 -->
<TableRow>
  <Button
    style="@style/CodeFont"
    android:text="注册"
  />
</TableRow>

</TableLayout>

运行结果依旧。

 

关于爱程序网 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助