当主题从Theme.AppCompat.Light.DarkActionBar扩展时,如何在整个应用程序中设置textview,edittexts的样式?
这不起作用,
<style name="myTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:textViewStyle">@style/myTextViewStyle</item>
<item name="textViewStyle">@style/myTextViewStyle</item>
</style>
<style name="myTextViewStyle" parent="android:Widget.TextView">
<item name="android:layout_marginLeft">5dp</item>
<item name="android:layout_marginRight">5dp</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:layout_marginBottom">5dp</item>
<item name="android:textColor">@android:color/black</item>
</style>
答案 0 :(得分:0)
<!-- Maintain *theme* naming convention Theme.ThemeName. It helps with organization. -->
<style name="Theme.MyApp" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textViewStyle">@style/Widget.MyApp.TextView</item>
<!-- AppCompat does not provide its own variant of textViewStyle attribute. -->
<item name="editTextStyle">@style/Widget.MyApp.EditText</item>
</style>
<!-- Maintain *style* naming convention Widget.ThemeName.WidgetName. -->
<!-- TextView is a simple widget, use the parent provided by platform. -->
<style name="Widget.MyApp.TextView" parent="android:Widget.TextView">
<!-- ... -->
</style>
<!-- EditText parent is provided by AppCompat. -->
<style name="Widget.MyApp.EditText" parent="Widget.AppCompat.EditText">
<!-- ... -->
</style>
只要您的应用或活动在清单中定义了android:theme="@style/Theme.MyApp
,它就会起作用。
笔记夫妇:
widgetNameStyle
。android:
。android:
前缀的变体和未前缀的变体,则不要覆盖它们!只有一个作品。TextView
和ProgressBar
)。android:theme
属性)。样式适用于小部件(style
属性)。