2017-02-20 6 views
1

Ich habe gelesen über das Anwenden von Stil für die ganze Anwendung in AndroidManifest, aber ich habe nicht gefunden, wie man Stil in Linear Layout anwendet.Wie man den allgemeinen Stil nur für ein LinearLayout anwendet

Zum Beispiel möchte ich ändern: Größe, Polsterung und Text allignment für alle diese Textviews:

<LinearLayout 
     android:orientation="horizontal" 
     android:layout_height="0dp" 
     android:layout_width="match_parent" 
     android:layout_weight="30" 
     style="@style/ItemTransacationHeader"> 
     <!--android:theme="@style/ItemTransacationHeader">--> 


     <TextView 
      android:text="Client" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:id="@+id/textView8" 
      android:layout_weight="10" 
      /> 

     <TextView 
      android:text="Quantity" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:id="@+id/textView9" 
      android:layout_weight="10" 
      /> 

     <TextView 
      android:text="Product Value" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:id="@+id/textView12" 
      android:layout_weight="10" 
      /> 


    </LinearLayout> 

so habe ich Stil

<style name="ItemTransacationHeader" parent="android:Theme"> 
    <item name="android:textSize">10dp</item> 
    <item name="android:textAlignment">textStart</item> 
    <item name="android:padding">4dp</item> 
</style> 

und ich habe auf vielfältige Weise versucht anzuwenden Dieser Stil zu LinearLayout

style="@style/ItemTransacationHeader" 
android:theme="@style/ItemTransacationHeader" 
app:theme="@style/ItemTransacationHeader" 

aber ich habe keine Ahnung, ist das sogar möglich (ich nehme an, ye s ist es) und wie kann ich das erreichen

Antwort

1
<LinearLayout 
    android:orientation="horizontal" 
    android:layout_height="0dp" 
    android:layout_width="match_parent" 
    android:layout_weight="30"> 

    <TextView 
     android:text="Client" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:id="@+id/textView8" 
     android:layout_weight="10" 
     style="@style/ItemTransacationHeader"/> 

    <TextView 
     android:text="Quantity" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:id="@+id/textView9" 
     android:layout_weight="10" 
     style="@style/ItemTransacationHeader"/> 

    <TextView 
     android:text="Product Value" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:id="@+id/textView12" 
     android:layout_weight="10" 
     style="@style/ItemTransacationHeader"/> 

</LinearLayout> 
0

Sie müssen @style für jeden TextView einzeln einstellen.

0

erstellen einen Stil für die Textview (Sie haben diesen Schritt getan, für Klarheit umbenannt)

<style name="AppTextStyle" parent="android:Theme"> 
    <item name="android:textSize">10dp</item> 
    <item name="android:textAlignment">textStart</item> 
    <item name="android:padding">4dp</item> 
</style> 

definieren es als Stil Ihr Textview ist in Thema Ihrer Anwendung:

<style name="AppTheme" parent="Theme.AppCompat.Light"> 
    ... 
    <item name="android:textViewStyle">@style/AppTextStyle</item> 
</style> 

Alle Ihre TextViews in Aktivitäten mit diesem Thema sollten jetzt AppTextStyle verwenden.

Siehe bestehende Frage: Setting global styles for Views in Android

Verwandte Themen