我正在尝试在对话框中使用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?
答案 0 :(得分:0)
使用Hyper-V的Visual Studio Android模拟器似乎存在问题。
使用HAXM在我的手机或Android SDK模拟器中安装应用时未出现问题。