2012-12-14 34 views
1

我想創建一個對話框與2 NumberPickers。我希望他們成爲默認的全息主題風格。我找不到任何好的例子。到目前爲止,我得到:需要幫助創建一個對話框與2 NumberPickers

LayoutInflater inflater = (LayoutInflater) 
     getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View npView = inflater.inflate(R.layout.number_picker_dialog, null); 
     NumberPicker minPicker = (NumberPicker) npView.findViewById(R.id.min_picker); 
     minPicker.setMaxValue(100); 
     minPicker.setMinValue(0); 
     NumberPicker maxPicker = (NumberPicker) npView.findViewById(R.id.max_picker); 
     maxPicker.setMaxValue(100); 
     maxPicker.setMinValue(0); 

     AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setTitle("Text Size:"); 
     builder.setView(npView); 
     builder.setPositiveButton("Okay", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int whichButton) { 

       } 
      }); 
     builder.setNegativeButton("Cancel", 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int whichButton) { 
        } 
       }); 
     dialog = builder.create(); 
     dialog.show(); 

number_picker_dialog XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:holo="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" 
android:gravity="center"> 

<NumberPicker 
    android:id="@+id/min_picker" 
    android:width="100dip" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:/> 

<NumberPicker 
    android:id="@+id/max_picker" 
    android:width="100dip" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"/> 

</LinearLayout> 

但ColorPicker的文字是白色的(如背景),和我不能設置NumberPicker的文字顏色。

如何設置textColor或者是否有人知道一個好的NumberPicker示例?

+0

樣式應用於具有textViewStyle你想要的文字顏色設置NumberPicker。 – gsingh2011

回答

1

我發現爲什麼我的NumberPicker沒有Holo.Light風格問題:

而不是通話:

LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View npView = inflater.inflate(R.layout.number_picker_dialog, null); 

我解決它通過調用:

​​
+0

不知道爲什麼這個改變爲你工作。 「前」和「後」陳述是相同的。你可以測試它 - 'getLayoutInflater()==(LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)'==>'true'。 – Vikram

0

我的方法是創建一個Custom Dialog類,如下所示。

public class CustomDialog extends Dialog { 
    public CustomDialog(Context context) { 
     super(context, R.style.customDialog); //use your style id from styles.xml 
    } 

    public void setNumberDialog() { 
      setContentView(R.layout.number_picker_dialog); 
      //add required listeners 
      show(); 
    } 
} 

從調用acitivty調用對話框。

new CustomDialog(context).setNumberDialog(); 

而且風格參數在styles.xml定義

<style name="customDialog" parent="android:Theme.Dialog"> 
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> 
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> 
    <item name="android:background">@android:color/transparent</item> 
    <item name="android:textColor">@color/textColorWhite</item> 
</style> 
+0

thnx爲您的幫助,但我發現真正的問題 – Luciano

0

嘗試:

<NumberPicker 
    style="@android:style/TextAppearance"> 
</NumberPicker> 
+0

thnx,爲您的幫助。沒有,但發現問題.. – Luciano