Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

android - Need help by creating a dialog with 2 NumberPickers

I'm trying to create a dialog with 2 NumberPickers. I would like them to be default Holo theme styled. I cant find any good examples. So far i got:

    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>

But the colorpicker text are white (Like the background), and i cant set the textColor of the NumberPicker.

How can i set the textColor or does anyone knows a good NumberPicker example?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I found the problem why my NumberPicker wasn't Holo.Light styled:

instead of calling:

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

i solved it by calling:

 View npView = getLayoutInflater().inflate(R.layout.number_picker_dialog, null);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...