Нужна помощь, создав диалог с 2 NumberPickers

1

Я пытаюсь создать диалог с 2 NumberPickers. Я бы хотел, чтобы они были дефолтными темами Holo. Я не могу найти хороших примеров. До сих пор я получил:

    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 белый (как и фон), и я не могу установить textColor для NumberPicker.

Как я могу установить textColor, или кто-нибудь знает хороший пример NumberPicker?

Теги:
numberpicker

3 ответа

1
Лучший ответ

Я нашел проблему, почему мой NumberPicker не был похож на Holo.Light:

вместо вызова:

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

я решил его, позвонив:

 View npView = getLayoutInflater().inflate(R.layout.number_picker_dialog, null);
  • 0
    Не уверен, почему это изменение сработало для вас. Операторы before и after эквивалентны. Вы можете проверить это - getLayoutInflater() == (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE) ==> true .
0

Попробуйте:

<NumberPicker
    style="@android:style/TextAppearance">
</NumberPicker>
  • 0
    спасибо за вашу помощь. Не нашел, но нашел проблему ..
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
    Спасибо за вашу помощь, но я нашел реальную проблему

Ещё вопросы

Сообщество Overcoder
Наверх
Меню