Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 需要通过创建带有2个NumberPicker的对话框获得帮助吗_Android_Numberpicker - Fatal编程技术网

Android 需要通过创建带有2个NumberPicker的对话框获得帮助吗

Android 需要通过创建带有2个NumberPicker的对话框获得帮助吗,android,numberpicker,Android,Numberpicker,我正在尝试创建一个带有2个数字图标的对话框。我想他们是默认全息主题风格。我找不到任何好的例子。到目前为止,我得到了: LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View npView = inflater.inflate(R.layout.number_picker

我正在尝试创建一个带有2个数字图标的对话框。我想他们是默认全息主题风格。我找不到任何好的例子。到目前为止,我得到了:

    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();
数字选择器对话框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>

但是颜色选择器文本是白色的(就像背景一样),我无法设置NumberPicker的文本颜色


如何设置textColor或是否有人知道一个好的NumberPicker示例?

我的方法是创建一个自定义对话框类,如下所示

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();
     }
}
从调用acitivity调用该对话框

 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>

@android:style/Animation.Dialog
状态未指定|调整盘
@android:彩色/透明
@颜色/文本颜色白色

我的方法是创建一个自定义对话框类,如下所示

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();
     }
}
从调用acitivity调用该对话框

 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>

@android:style/Animation.Dialog
状态未指定|调整盘
@android:彩色/透明
@颜色/文本颜色白色
试试:

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

试试:

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

我发现了为什么我的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);

我发现了为什么我的号码牌不是全息的问题。灯光样式:

而不是打电话:

   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);

将样式应用于设置了所需文本颜色的textViewStyle的NumberPicker。将样式应用于设置了所需文本颜色的textViewStyle的NumberPicker。thnx感谢您的帮助,但我发现了真正的问题thnx感谢您的帮助,但我发现了真正的问题不确定此更改为什么适用于您。前后的
语句是等效的。您可以测试它-
getLayoutInflater()==(LayoutInflater)this.getSystemService(Context.LAYOUT\u INFLATER\u SERVICE)
=>
true
。不确定为什么此更改对您有效。前后的
语句是等效的。您可以测试它-
getLayoutInflater()==(LayoutInflater)this.getSystemService(Context.LAYOUT\u INFLATER\u SERVICE)
=>
true