2010-08-10 29 views
7

Tôi có một lớp học, TextViewStyled, kéo dài TextViewAndroid áp dụng phong cách để tùy chỉnh TextView

Trong XML chủ đề của tôi, làm thế nào để áp dụng một phong cách cho tất cả TextViewStyled widget của tôi trên hoạt động với một chủ đề được lựa chọn?

Tôi có chủ đề đơn giản này, nhưng tôi muốn giới hạn kiểu Đen Vàng thành TextViewStyled Tiện ích mà không chỉ định Vàng Đen trong thuộc tính kiểu TextViewStyled. Đây là một trong nhiều chủ đề mà sẽ được chuyển tự động .:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="MyThemeOneofMany" parent="android:Theme.NoTitleBar.Fullscreen"> 
    <item name="android:???????????">@style/TextViewStyled_Black_Gold</item> 
    </style> 

    <style name="TextViewStyled_Black_Gold" parent="@android:style/Widget.TextView">    
      <item name="android:background">#1E1921</item>   
      <item name="android:textColor">#A85E4F</item> 
      <item name="android:textColorLink">#FFBC4F</item> 
      <item name="android:textStyle">normal</item>    
     </style> 


</resources> 

Trả lời

2

tôi thấy rằng việc cập nhật các phong cách hoạt động khi trọng các lớp cơ sở textview sau sự kiện inflation.

+0

làm thế nào để bạn cập nhật những phong cách? – schwiz

+0

bạn có thể vui lòng cung cấp mã, cách bạn thực hiện không? hoặc những gì bạn đưa vào ??? marks nauman

2

Để thiết lập phong cách cho TextView trong Theme tùy chỉnh của bạn sử dụng cái tên "android: textViewStyle":

<style name="MyThemeOneofMany" parent="android:Theme.NoTitleBar.Fullscreen"> 
    <item name="android:textViewStyle">@style/TextViewStyled_Black_Gold</item> 
</style> 

Tìm thấy nó khi nhìn qua themes.xml android chính thức [click].

9

Đối AppCompat chủ đề (2.3.3+):

<!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="android:textViewStyle">@style/PizzaSizeWidget</item> 
    </style> 

    <style name="CustomTextView" parent="@android:style/TextAppearance.Widget.TextView"> 
     <item name="android:background">#1E1921</item> 
     <item name="android:textColor">#A85E4F</item> 
     <item name="android:textStyle">normal</item> 
     <item name="android:textSize">93sp</item> 
    </style> 
+1

nên là 'CustomTextView' thay vì' PizzaSizeWidget'? –

Các vấn đề liên quan