【问题标题】:Using SimonVT number picker and unable to inflate xml使用 SimonVT 数字选择器并且无法膨胀 xml
【发布时间】:2014-01-08 05:09:40
【问题描述】:

所以我正在使用SimonVT number picker 尝试创建一个与姜饼一起使用的数字选择器。不幸的是,当我尝试将其设置为对话框时,它会在尝试膨胀 xml 时崩溃。老实说,我在这上面花了一段时间,但看在我的爱上,我无法弄清楚。其他人可以吗?

这是崩溃的地方:

import net.simonvt.numberpicker.NumberPicker;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;

public class setSnoozeMethodDialog extends DialogFragment{

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    View view = getActivity().getLayoutInflater().inflate(R.layout.set_snooze_dialog, null);

    NumberPicker np = (NumberPicker) view.findViewById(R.id.numberPicker);
    np.setMaxValue(20);
    np.setMinValue(0);
    np.setFocusable(true);
    np.setFocusableInTouchMode(true);

    builder.setView(view);

    return builder.create();
}

这是无法膨胀的 xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center">

<net.simonvt.numberpicker.NumberPicker
    android:id="@+id/numberPicker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
</LinearLayout>

这是错误

01-07 23:44:33.308: E/AndroidRuntime(623): FATAL EXCEPTION: main
01-07 23:44:33.308: E/AndroidRuntime(623): android.view.InflateException: Binary XML file line #8: Error inflating class net.simonvt.numberpicker.NumberPicker
01-07 23:44:33.308: E/AndroidRuntime(623):  at android.view.LayoutInflater.createView(LayoutInflater.java:518)
01-07 23:44:33.308: E/AndroidRuntime(623):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
01-07 23:44:33.308: E/AndroidRuntime(623):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
01-07 23:44:33.308: E/AndroidRuntime(623):  at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
01-07 23:44:33.308: E/AndroidRuntime(623):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-07 23:44:33.308: E/AndroidRuntime(623):  at     android.view.LayoutInflater.inflate(LayoutInflater.java:276)

我已经把这些放在我的清单中了

        <activity
        android:name="net.simonvt.numberpicker.samples.DarkThemeActivity"
        android:theme="@style/SampleTheme" />
        <activity
        android:name="net.simonvt.numberpicker.samples.LightThemeActivity"
        android:theme="@style/SampleTheme.Light" />

这是在我的 value 文件夹中的 theme.xml 中

<resources>

<style name="SampleTheme" parent="android:Theme">
    <item name="numberPickerStyle">@style/NPWidget.Holo.NumberPicker</item>
</style>

<style name="SampleTheme.Light" parent="android:Theme.Light">
    <item name="numberPickerStyle">@style/NPWidget.Holo.Light.NumberPicker</item>
</style>

【问题讨论】:

    标签: java android xml


    【解决方案1】:

    想通了。我需要添加

    <resources>
    
    <style name="SampleTheme" parent="android:Theme">
        <item name="numberPickerStyle">@style/NPWidget.Holo.NumberPicker</item> </style>
    
    <style name="SampleTheme.Light" parent="android:Theme.Light">
        <item name="numberPickerStyle">@style/NPWidget.Holo.Light.NumberPicker</item> </style>
    

    到我的样式文件,而不是主题文件。

    【讨论】:

      猜你喜欢
      • 2013-08-27
      • 1970-01-01
      • 2013-03-28
      • 2020-04-26
      • 1970-01-01
      • 2019-06-10
      • 1970-01-01
      • 1970-01-01
      • 2012-12-10
      相关资源
      最近更新 更多