Need help by creating a dialog with 2 NumberPickers

北战南征 提交于 2019-11-29 17:19:51

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

My approach was to create a Custom Dialog class as show below.

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

Invoke the dialog from calling acitivty.

 new CustomDialog(context).setNumberDialog(); 

And the style parameters are defined in 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>

Try :

<NumberPicker
    style="@android:style/TextAppearance">
</NumberPicker>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!