8

如何通过样式设置 LinearLayout 的 TextView 子项的样式。像这样的东西:

<style name="MyLinearayoutStyle" parent="MyParentStyle">
    <item name="android:background">@drawable/mybackground</item>
    <item name="android:padding>5dp</item>
    // Here i need to define my textview style
</style>


<style name="MyTextViewStyle> parent="AnotherParentStyle">
    <item name="android:textColor">@color/Black</item>
    <item name="android:textSize">15sp</item>
</style>

我尝试了 android:TextAppearance 和 android:textStyle,但这没有用。

4

2 回答 2

8

更改主题定义((存储在 res/values/styles.xml 中):

<?xml version="1.0" encoding="utf-8"?> 
<resources>   
<style name="MyTheme" parent="android:Theme.Light">    
    <item name="android:textAppearance">@style/MyDefaultTextAppearance</item> 
</style>    
     <style name="MyDefaultTextAppearance" parent="@android:style/TextAppearance">    
     <item name="android:textSize">12sp</item>     
    <item name="android:textColor">#333</item>    
     <item name="android:textStyle">bold</item>   
    </style> 
    </resources>
于 2013-05-17T07:14:15.313 回答
5

膨胀你TextView的例子:

*textview.xml*

<?xml version="1.0" encoding="utf-8"?>
<TextView 
 style="@+style/MyLinearayoutStyle"
 />

activity.getLayoutInflater().inflate(R.layout.textview,(parent view), true);

于 2013-05-17T07:10:19.357 回答