错误在> = 23中膨胀类Seekbar

时间:2017-02-01 05:26:22

标签: java android android-6.0-marshmallow seekbar

我的代码在kitkat中工作,没有例外。棉花糖发生以下错误。

Java文件

class MyServAdapter extends RecyclerView.Adapter<MyServAdapter.MyViewHolder> {
    int icons_red[] = {R.drawable.red_service, R.drawable.red_tire, R.drawable.red_oil_car, R.drawable.red_pollutn, R.drawable.red_car_insurance};

    public class MyViewHolder extends RecyclerView.ViewHolder {
        public TextView sevice_name, due_time;
        public ImageView img;
        public SeekBar seekBar;

        public MyViewHolder(View view) {
            super(view);
            sevice_name = (TextView) view.findViewById(R.id.serv_name);
            due_time = (TextView) view.findViewById(R.id.due_date);
            //  servi_time_words = (TextView) view.findViewById(R.id.serv_time_in_words);
            img = (ImageView) view.findViewById(R.id.serv_icon);
            seekBar = (SeekBar) view.findViewById(R.id.serv_progress);
        }
    }

    public MyServAdapter(ServiceDetail service_detail) {
        this.service_detail = service_detail;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.custom_service_item, parent, false); //here i'm getting error 
        return new MyViewHolder(itemView);
    }
}

错误记录

FATAL EXCEPTION: main
Process: com.eoninfotech.eurotrack, PID: 19864
  android.view.InflateException: Binary XML file line #39: Binary XML file line #39: Error inflating class SeekBar
  at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
  at com.eoninfotech.eurotrack.Fragmentss.MyServAdapter.onCreateViewHolder(MyServAdapter.java:53)
  at com.eoninfotech.eurotrack.Fragmentss.MyServAdapter.onCreateViewHolder(MyServAdapter.java:24)
  at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5836)
  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5060)
  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4970)
  at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029)
  at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1414)
  at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)
  at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)
  at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3315)
  at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3124)
  at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3568)
  at android.view.View.layout(View.java:17993)
  at android.view.ViewGroup.layout(ViewGroup.java:5817)
  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
  at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
  at android.view.View.layout(View.java:17993)
  at android.view.ViewGroup.layout(ViewGroup.java:5817)
  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
  at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
  at android.view.View.layout(View.java:17993)
  at android.view.ViewGroup.layout(ViewGroup.java:5817)
  at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:131)
  at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
  at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1364)
  at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:846)
  at android.view.View.layout(View.java:17993)
  at android.view.ViewGroup.layout(ViewGroup.java:5817)
  at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1197)
  at android.view.View.layout(View.java:17993)
  at android.view.ViewGroup.layout(ViewGroup.java:5817)
  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
  at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
  at android.view.View.layout(View.java:17993)
  at android.view.ViewGroup.layout(ViewGroup.java:5817)
  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
  at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
  at android.view.View.layout(View.java:17993)
  at android.view.ViewGroup.layout(ViewGroup.java:5817)
  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
  at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
  at android.view.View.layout(View.java:17993)
  at android.view.ViewGroup.layout(ViewGroup.java:5817)
  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
  at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
  at android.view.View.layout(View.java:17993)
  at android.view.ViewGroup.layout(ViewGroup.java:5817)
  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
  at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
  at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:3172)
  at android.view.View.layout(View.java:1

在我的xml中,我自定义了我的SeekBar,可绘制文件同时添加到drawable和drawable-v21中。 Drawble文件不是image和xml文件。

 <SeekBar
     android:id="@+id/serv_progress"
     android:layout_width="match_parent"
     android:layout_height="7dp"
     android:max="100"
     android:progressDrawable="@drawable/custom_progressbar"
     android:thumb="@drawable/thumbb" />

drawable是-custom_progressbar.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">
        <shape android:shape="rectangle" >
            <corners android:radius="5dp" />

            <gradient

                android:endColor="#979797"
                android:startColor="#979797" />
        </shape>
    </item>
    <item android:id="@+id/progressshape">
        <clip>
            <shape android:shape="rectangle" >
                <corners android:radius="5dp" />

                <gradient

                    android:endColor="@color/red"
                    android:centerColor="#ffea03"
                    android:startColor="#27e883" />
            </shape>
        </clip>
    </item>

</layer-list>

1 个答案:

答案 0 :(得分:1)

谢谢大家 问题解决了。在marshmallow我不能添加拇指作为svg:| 所以我删除android:thumb="@drawable/thumbb"此属性,代码现在正在运行