我试图在我的android项目中添加一个不错的自定义搜索栏。 我使用了this和this教程,我得到了同样的异常。我不认为这两个教程都是错的......我的错误是什么?
我的xml文件:
seekbar_progress_bg.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<clip >
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:antialias="true"
android:dither="false"
android:filter="false"
android:gravity="left"
android:src="@drawable/green">
</bitmap>
</clip>
</item>
</layer-list>
seekbar_progress.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@android:id/background">
<nine-patch
xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true"
android:src="@drawable/whitepatch">
</nine-patch>
</item>
<item android:id="@android:id/secondaryProgress">
<clip >
<shape >
<gradient
android:angle="270"
android:centerColor="#80127fb1"
android:centerY="0.75"
android:endColor="#a004638f"
android:startColor="#80028ac8">
</gradient>
</shape>
</clip>
</item>
<item
android:id="@android:id/progress"
android:drawable="@drawable/seekbar_progress_bg">
</item>
</layer-list>
我的搜索栏:
<SeekBar
android:id="@+id/pagesSeekBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/textView1"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:progressDrawable="@drawable/seekbar_progress"
android:thumb="@drawable/shine_btn"
android:maxHeight="9dp"
android:minHeight="9dp"/>
在这里查看我的logcat:
07-31 13:25:11.996: E/AndroidRuntime(5124): FATAL EXCEPTION: main
07-31 13:25:11.996: E/AndroidRuntime(5124): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackage.myproject/com.mypackage.myproject.reader.Reader}: android.view.InflateException: Binary XML file line #62: Error inflating class android.widget.SeekBar
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.os.Handler.dispatchMessage(Handler.java:99)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.os.Looper.loop(Looper.java:123)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.app.ActivityThread.main(ActivityThread.java:3687)
07-31 13:25:11.996: E/AndroidRuntime(5124): at java.lang.reflect.Method.invokeNative(Native Method)
07-31 13:25:11.996: E/AndroidRuntime(5124): at java.lang.reflect.Method.invoke(Method.java:507)
07-31 13:25:11.996: E/AndroidRuntime(5124): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
07-31 13:25:11.996: E/AndroidRuntime(5124): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
07-31 13:25:11.996: E/AndroidRuntime(5124): at dalvik.system.NativeStart.main(Native Method)
07-31 13:25:11.996: E/AndroidRuntime(5124): Caused by: android.view.InflateException: Binary XML file line #62: Error inflating class android.widget.SeekBar
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
07-31 13:25:11.996: E/AndroidRuntime(5124): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-31 13:25:11.996: E/AndroidRuntime(5124): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:209)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.app.Activity.setContentView(Activity.java:1657)
07-31 13:25:11.996: E/AndroidRuntime(5124): at com.mypackage.myproject.reader.Reader.onCreate(Reader.java:87)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
07-31 13:25:11.996: E/AndroidRuntime(5124): ... 11 more
07-31 13:25:11.996: E/AndroidRuntime(5124): Caused by: java.lang.reflect.InvocationTargetException
07-31 13:25:11.996: E/AndroidRuntime(5124): at java.lang.reflect.Constructor.constructNative(Native Method)
07-31 13:25:11.996: E/AndroidRuntime(5124): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
07-31 13:25:11.996: E/AndroidRuntime(5124): ... 23 more
07-31 13:25:11.996: E/AndroidRuntime(5124): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/seekbar_progress.xml from drawable resource ID #0x7f02002f
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.content.res.Resources.loadDrawable(Resources.java:1697)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.widget.ProgressBar.<init>(ProgressBar.java:179)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.widget.AbsSeekBar.<init>(AbsSeekBar.java:61)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.widget.SeekBar.<init>(SeekBar.java:81)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.widget.SeekBar.<init>(SeekBar.java:77)
07-31 13:25:11.996: E/AndroidRuntime(5124): ... 26 more
07-31 13:25:11.996: E/AndroidRuntime(5124): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #5: <nine-patch> requires a valid 9-patch source image
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.graphics.drawable.NinePatchDrawable.inflate(NinePatchDrawable.java:267)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.graphics.drawable.LayerDrawable.inflate(LayerDrawable.java:154)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
07-31 13:25:11.996: E/AndroidRuntime(5124): at android.content.res.Resources.loadDrawable(Resources.java:1694)
07-31 13:25:11.996: E/AndroidRuntime(5124): ... 31 more
在图形布局中,我可以在搜索栏上清楚地看到我的新皮肤,但是当我尝试运行应用程序时,它只是崩溃。
请帮助我,我做错了什么?