在style.xml中设置底层TextView的样式

时间:2013-05-17 06:54:27

标签: android styles textview themes

如何通过样式设置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,但这并没有用。

2 个答案:

答案 0 :(得分:7)

更改主题定义((存储在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>

答案 1 :(得分:5)

TextView充气,例如:

*textview.xml*

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

  

activity.getLayoutInflater()。膨胀(R.layout.textview,   (父视图),true);