【发布时间】:2015-05-05 19:47:42
【问题描述】:
我有一个自定义视图“address_view.xml”,它显示一个人的姓名和街道地址,定义如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="John Smith"/>
<TextView
android:id="@+id/street_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
tools:text="1 Main St."/>
</LinearLayout>
此视图在我的应用程序的多个页面中使用,但每个 TextView 有 2 种字体、文本颜色和大小的变化。
是否可以为这个视图创建“主题”,分别设置名称和地址 TextViews 的 textFont/textColor?例如,我想做这样的事情:
<com.example.view.AddressView
...
style="@style/Theme1" />
将“名称”TextView 设置为使用 FontA、ColorA 和 Size1,并将“地址”TextView 设置为使用 FontB、ColorB 和 Size2。
这样,我可以在某些页面上使用 Theme1,并使用字体/颜色/大小的第二种组合创建另一个“Theme2”并在其他页面上使用它。
【问题讨论】:
标签: android android-view android-styles