膨胀 class 搜索栏时出错
Error inflating class Seekbar
我正在尝试将自定义视图扩展到警报对话框中。
这里是创建对话框和放大视图的代码:
SeekBar volume = new SeekBar(this);
volume = FindViewById<SeekBar>(Resource.Id.seekbar_volume);
LayoutInflater inflater = (LayoutInflater)GetSystemService(LayoutInflaterService);
Exception at this line --> AlertDialog.Builder volumeDialog = new AlertDialog.Builder(this)
.SetTitle("How much milk the baby drank?")
.SetView(inflater.Inflate(Resource.Layout.volume_seekbar_layout, null))
.SetCancelable(false);
volumeDialog.SetPositiveButton("OK", (senderAlert, args) => // OK button click
{
Toast.MakeText(this, volume.Progress.ToString(), ToastLength.Short).Show();
}).Create().Show();
这里是个例外:
Unhandled Exception:
Android.Views.InflateException: Binary XML file line #1: Binary XML
file line #1: Error inflating class Seekbar
这里是 volume_seekbar_layout.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/volume_seekbar_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Seekbar android:id="@+id/seekbar_volume"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</Seekbar>
</RelativeLayout>
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="FeedingTime.FeedingTime" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<uses-sdk />
<application android:icon="@drawable/Icon" android:label="Feeding Time" android:theme="@style/AppTheme">
</application>
</manifest>
仅当volume_seekbar_layout 中有Seekbar 元素时才会抛出异常。例如,当我尝试使用内部的 TextView 对其进行充气时,它会正常工作。
您在SeekBar 中输入错误。 SeekBar 使用 Seek 和 Bar 这两个词的 UpperCamel 大小写:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/volume_seekbar_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<SeekBar android:id="@+id/seekbar_volume"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</SeekBar>
</RelativeLayout>
我正在尝试将自定义视图扩展到警报对话框中。
这里是创建对话框和放大视图的代码:
SeekBar volume = new SeekBar(this);
volume = FindViewById<SeekBar>(Resource.Id.seekbar_volume);
LayoutInflater inflater = (LayoutInflater)GetSystemService(LayoutInflaterService);
Exception at this line --> AlertDialog.Builder volumeDialog = new AlertDialog.Builder(this)
.SetTitle("How much milk the baby drank?")
.SetView(inflater.Inflate(Resource.Layout.volume_seekbar_layout, null))
.SetCancelable(false);
volumeDialog.SetPositiveButton("OK", (senderAlert, args) => // OK button click
{
Toast.MakeText(this, volume.Progress.ToString(), ToastLength.Short).Show();
}).Create().Show();
这里是个例外:
Unhandled Exception:
Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class Seekbar
这里是 volume_seekbar_layout.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/volume_seekbar_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Seekbar android:id="@+id/seekbar_volume"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</Seekbar>
</RelativeLayout>
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="FeedingTime.FeedingTime" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<uses-sdk />
<application android:icon="@drawable/Icon" android:label="Feeding Time" android:theme="@style/AppTheme">
</application>
</manifest>
仅当volume_seekbar_layout 中有Seekbar 元素时才会抛出异常。例如,当我尝试使用内部的 TextView 对其进行充气时,它会正常工作。
您在SeekBar 中输入错误。 SeekBar 使用 Seek 和 Bar 这两个词的 UpperCamel 大小写:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/volume_seekbar_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<SeekBar android:id="@+id/seekbar_volume"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</SeekBar>
</RelativeLayout>