2016-03-19 12 views
0

誰かが私にViewGroupクラスのスタイルを設定する方法を教えてもらえますか??私はインターネットで解決策を見つけようとしましたが、成功しませんでした。ViewGroupのスタイル/テーマを設定する方法

ありがとうございます。

+0

あなたは何を試しましたか? –

答えて

1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_vertical" 
    android:orientation="horizontal" 
    android:paddingLeft="16dp" 
    android:paddingRight="16dp" 
    style="@style/AppTheme" // <--------- reference your style here 
    > 
</LinearLayout> 
+0

あなたの答えをありがとうが、私はViewGroupクラスを意味し、残念に残念です。 – Samuel

1

次のようにあなたのresフォルダ内のstyle.xmlファイルでスタイルを定義します。

<?xml version="1.0" encoding="utf-8"?> 
<resources xmlns:android="http://schemas.android.com/apk/res/android"> 

<style name="Style_Button_SquareGrayLight"> 
     <item name="android:textColor">@color/white</item> 
     <item name="android:background">@drawable/button_basic_gray_rounded_corners</item> 
     <item name="android:textSize">@dimen/button</item> 
     <item name="android:typeface">sans</item> 
     <item name="android:textStyle">bold</item> 
     <item name="android:layout_height">35dip</item> 
     <item name="android:paddingLeft">10dip</item> 
     <item name="android:paddingRight">10dip</item> 
     <item name="android:singleLine">true</item> 
    </style> 
</resources> 

私のスタイル名の上に与えられたように、「Style_Button_SquareGrayLight」で、今、あなたは、任意のビューまたはのViewGroupにこのスタイルを設定することができます次のようにstyle = "@ style/AppThemeName"プロパティを使用します。

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="@dimen/page_left_padding" 
     android:layout_marginRight="0dip" 
     android:layout_marginTop="@dimen/page_top_padding" 
style="@style/Style_Button_SquareGrayLight"/> 

同様に、Button、TextViewなどのビューも設定できます。

+0

あなたの答えをありがとうございますが、私はViewGroup **クラス**を意味しました。 – Samuel

関連する問題