我试图在对话框中使用NumberPicker。
当我将NumberPicker添加到视图中时,如下所示:

我的对话框xml文件看起来非常简单,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<NumberPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/numberPicker"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>我的代码很简单:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = (LayoutInflater)builder.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout inflated = (RelativeLayout)inflater.inflate(R.layout.dialog_button_delay, (ViewGroup)getView());
final NumberPicker pick = (NumberPicker) inflated.findViewById(R.id.numberPicker);
String[] minuteValues = new String[37];
for (int i = 0; i < minuteValues.length; i++) {
minuteValues[i] = String.valueOf(i*5);
}
pick.setWrapSelectorWheel(false);
pick.setMinValue(0);
pick.setMaxValue(36);
pick.setDisplayedValues(minuteValues);
builder.setView(inflated);舱单档案:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.familyfood.familyfood">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity
android:name=".MainActivity"
android:label="@string/title_start">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AddFoodActivity" />
<activity
android:name=".LoginActivity"
android:label="@string/title_activity_login"/>
</application>
</manifest>样式xml文件:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
</resources>添加android:theme="@android:style/Theme.Dialog"会产生以下可视化结果:

有人知道为什么我不能使用MaterialDesign NumberPicker吗?
发布于 2016-10-29 09:48:33
使用Hyper-V的仿真程序似乎存在问题。
在我的手机或使用HAXM的Android模拟器上安装应用程序时,没有出现问题。
https://stackoverflow.com/questions/40299804
复制相似问题