2013-05-22 6 views
5
私は以下のコードでスピナーのTEXTSIZEや色を変更することができませんでした

スピナーのテキストサイズは変更されませんか?

<Spinner 
    android:id="@+id/spinner1" 
    style="@style/submitspinner" 
    android:layout_weight="2" 
    android:entries="@array/a_code" 
    android:prompt="@string/p_code" /> 

スタイル:

<style name="submitspinner" parent="@android:TextAppearance.Widget.TextView.SpinnerItem"> 
    <item name="android:layout_width">wrap_content</item> 
    <item name="android:layout_height">match_parent</item> 
    <item name="android:layout_margin">10sp</item> 
    <item name="android:textColor">@android:color/holo_blue_dark</item> 
    <item name="android:textSize">@dimen/pt</item> 
</style> 

それは私がスピナーのテキストサイズや色の変更を増やすことができますどのように、同じように見えますか?

答えて

13

カスタムスピナーのために何をすべきですか?そのように、スピナー内の文字列のためのテンプレートとして機能しますEA単一のXML:あなたはJavaであなたのスピナーアダプタを作成するときに

<?xml version="1.0" encoding="UTF-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/standard_spinner_format" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="@dimen/pt" 
    android:textColor="@android:color/holo_blue_dark"/> 

次の操作を行います

ArrayAdapter<CharSequence> typeAdapter = ArrayAdapter.createFromResource(getActivity(), 
      R.array.my_spinner_array, R.layout.custom_xml_spinner_layout); //change the last argument here to your xml above. 
    typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
+0

をSPにそれを変更しました。コードを介してアダプタを設定せずにスピナーをスタイルする方法があります。方法を示す答えを加えました。 –

1

ここにあなたのスピナー

をカスタマイズするには、私は一度、それはuが必要なすべてを持って

http://stephenpengilley.blogspot.be/2013/01/android-custom-spinner-tutorial.html

を使用良いチュートリアルです。あなたの 'スタイル' でも

uが持っている:

<item name="android:layout_margin">10sp</item> 

変更は、それはuが測定する単位についての詳細を見つけることができ、ここで

SP =テキストサイズを10dpする

What is the difference between "px", "dp", "dip" and "sp" on Android?

+0

おかげで、私はOPはアンドロイド '経由でスタティックエントリを使用している –

27

経由XML

静的にSpinnerエントリをXMLで設定している場合に役立ちます。

あなたがコードを介して、あなたのスピナーを作成しているが、あなたはandroid:entriesを使用して、つまり、XMLを経由してあなたのスピナーエントリを設定している場合は、あなたがテキストサイズおよびその他の属性を調整することができます場合は、上記の答えは仕事以下の2つのテーマの設定:彼のスピナーを移入するためにentries`:あなたのres /値/のstyles.xmlで

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

    <style name="AppBaseTheme" parent="android:Theme.Holo"> 
    </style> 

    <!-- Application theme. --> 
    <style name="AppTheme" parent="AppBaseTheme"> 

     <!-- For the resting Spinner style --> 
     <item name="android:spinnerItemStyle"> 
      @style/spinnerItemStyle 
     </item> 

     <!-- For each individual Spinner list item once clicked on --> 
     <item name="android:spinnerDropDownItemStyle"> 
      @style/spinnerDropDownItemStyle 
     </item> 

    </style> 

    <style name="spinnerItemStyle"> 
     <item name="android:padding">10dp</item> 
     <item name="android:textSize">20sp</item> 
     <item name="android:textColor">#FFFFFF</item> 
    </style> 

    <style name="spinnerDropDownItemStyle"> 
     <item name="android:padding">20dp</item> 
     <item name="android:textSize">30sp</item> 
     <item name="android:textColor">#FFFFFF</item> 
    </style> 

</resources> 
+3

これは良い情報です[+1] ....