迷失了TextInputLayout和样式

时间:2016-06-23 12:53:07

标签: android android-layout

我正在尝试在我的应用程序中使用TextInputLayout,在Fragment中使用RecyclerView。所以,我在Fragment的onCreateView:

final IuAdapter adapter=new IuAdapter(datos);

这是IuAdapter类:

public class IuAdapter extends RecyclerView.Adapter<IuAdapter.ViewHolder> implements View.OnClickListener{

private ArrayList<Model> datos;
private View.OnClickListener listener;

public IuAdapter(ArrayList<Model> datos) {
    this.datos = datos;
}

@Override
public void onClick(View v) {
    if(listener != null)
        listener.onClick(v);
}

public void setOnClickListener(View.OnClickListener listener) {
    this.listener = listener;
}

@Override
public IuAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    try{
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.rowlayout, parent, false);//Exception is thrown here
        itemView.setOnClickListener(this);
        ViewHolder holder=new ViewHolder(itemView);
        return holder;
    }catch (Exception e){
        e.printStackTrace();
    }


    return null;
}

@Override
public void onBindViewHolder(IuAdapter.ViewHolder holder, int position) {
    Model item=datos.get(position);

    holder.colocarModelo(item);
}

@Override
public int getItemCount() {
    return datos.size();
}

public static class ViewHolder extends RecyclerView.ViewHolder{

    private TextInputLayout textInputLayout;

    public ViewHolder(View itemView) {
        super(itemView);
        textInputLayout=(TextInputLayout)itemView.findViewById(R.id.textInputLayout);
    }

    private void colocarModelo(Model model){
        textInputLayout.setHint(model.getHint());
        textInputLayout.getEditText().setText(model.getValor());
    }
}

}

使用此代码,在调用它时,我收到一个异常:

06-23 13:52:00.787 10873-10873/es.infaplic.gibmov W/System.err: android.view.InflateException: Binary XML file line #5: Error inflating class android.support.design.widget.TextInputLayout
06-23 13:52:00.807 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
06-23 13:52:00.807 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
06-23 13:52:00.807 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
06-23 13:52:00.817 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
06-23 13:52:00.817 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
06-23 13:52:00.817 10873-10873/es.infaplic.gibmov W/System.err:     at es.infaplic.gibmov.Adapters.IuAdapter.onCreateViewHolder(IuAdapter.java:40)
06-23 13:52:00.817 10873-10873/es.infaplic.gibmov W/System.err:     at es.infaplic.gibmov.Adapters.IuAdapter.onCreateViewHolder(IuAdapter.java:17)
06-23 13:52:00.817 10873-10873/es.infaplic.gibmov W/System.err:     at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5116)
06-23 13:52:00.817 10873-10873/es.infaplic.gibmov W/System.err:     at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4416)
06-23 13:52:00.817 10873-10873/es.infaplic.gibmov W/System.err:     at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4326)
06-23 13:52:00.817 10873-10873/es.infaplic.gibmov W/System.err:     at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1955)
06-23 13:52:00.817 10873-10873/es.infaplic.gibmov W/System.err:     at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1364)
06-23 13:52:00.817 10873-10873/es.infaplic.gibmov W/System.err:     at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1327)
06-23 13:52:00.817 10873-10873/es.infaplic.gibmov W/System.err:     at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:556)
06-23 13:52:00.817 10873-10873/es.infaplic.gibmov W/System.err:     at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2713)
06-23 13:52:00.817 10873-10873/es.infaplic.gibmov W/System.err:     at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3011)
06-23 13:52:00.827 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.View.layout(View.java:14948)
06-23 13:52:00.827 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.ViewGroup.layout(ViewGroup.java:4631)
06-23 13:52:00.827 10873-10873/es.infaplic.gibmov W/System.err:     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
06-23 13:52:00.827 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.View.layout(View.java:14948)
06-23 13:52:00.827 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.ViewGroup.layout(ViewGroup.java:4631)
06-23 13:52:00.827 10873-10873/es.infaplic.gibmov W/System.err:     at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1627)
06-23 13:52:00.827 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.View.layout(View.java:14948)
06-23 13:52:00.827 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.ViewGroup.layout(ViewGroup.java:4631)
06-23 13:52:00.827 10873-10873/es.infaplic.gibmov W/System.err:     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
06-23 13:52:00.827 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.View.layout(View.java:14948)
06-23 13:52:00.837 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.ViewGroup.layout(ViewGroup.java:4631)
06-23 13:52:00.837 10873-10873/es.infaplic.gibmov W/System.err:     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
06-23 13:52:00.837 10873-10873/es.infaplic.gibmov W/System.err:     at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
06-23 13:52:00.837 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.View.layout(View.java:14948)
06-23 13:52:00.837 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.ViewGroup.layout(ViewGroup.java:4631)
06-23 13:52:00.837 10873-10873/es.infaplic.gibmov W/System.err:     at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:374)
06-23 13:52:00.837 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.View.layout(View.java:14948)
06-23 13:52:00.837 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.ViewGroup.layout(ViewGroup.java:4631)
06-23 13:52:00.837 10873-10873/es.infaplic.gibmov W/System.err:     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
06-23 13:52:00.837 10873-10873/es.infaplic.gibmov W/System.err:     at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
06-23 13:52:00.837 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.View.layout(View.java:14948)
06-23 13:52:00.837 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.ViewGroup.layout(ViewGroup.java:4631)
06-23 13:52:00.837 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1991)
06-23 13:52:00.847 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1748)
06-23 13:52:00.847 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
06-23 13:52:00.847 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5703)
06-23 13:52:00.847 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
06-23 13:52:00.847 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.Choreographer.doCallbacks(Choreographer.java:574)
06-23 13:52:00.847 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.Choreographer.doFrame(Choreographer.java:544)
06-23 13:52:00.847 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
06-23 13:52:00.847 10873-10873/es.infaplic.gibmov W/System.err:     at android.os.Handler.handleCallback(Handler.java:743)
06-23 13:52:00.847 10873-10873/es.infaplic.gibmov W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
06-23 13:52:00.847 10873-10873/es.infaplic.gibmov W/System.err:     at android.os.Looper.loop(Looper.java:136)
06-23 13:52:00.847 10873-10873/es.infaplic.gibmov W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5212)
06-23 13:52:00.847 10873-10873/es.infaplic.gibmov W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
06-23 13:52:00.847 10873-10873/es.infaplic.gibmov W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)
06-23 13:52:00.847 10873-10873/es.infaplic.gibmov W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
06-23 13:52:00.857 10873-10873/es.infaplic.gibmov W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
06-23 13:52:00.857 10873-10873/es.infaplic.gibmov W/System.err:     at dalvik.system.NativeStart.main(Native Method)
06-23 13:52:00.857 10873-10873/es.infaplic.gibmov W/System.err: Caused by: java.lang.reflect.InvocationTargetException
06-23 13:52:00.867 10873-10873/es.infaplic.gibmov W/System.err:     at java.lang.reflect.Constructor.constructNative(Native Method)
06-23 13:52:00.867 10873-10873/es.infaplic.gibmov W/System.err:     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
06-23 13:52:00.867 10873-10873/es.infaplic.gibmov W/System.err:     at android.view.LayoutInflater.createView(LayoutInflater.java:594)
06-23 13:52:00.867 10873-10873/es.infaplic.gibmov W/System.err:     ... 54 more
06-23 13:52:00.867 10873-10873/es.infaplic.gibmov W/System.err: Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
06-23 13:52:00.877 10873-10873/es.infaplic.gibmov W/System.err:     at android.content.res.TypedArray.getColor(TypedArray.java:327)
06-23 13:52:00.877 10873-10873/es.infaplic.gibmov W/System.err:     at android.support.design.widget.CollapsingTextHelper.setCollapsedTextAppearance(CollapsingTextHelper.java:166)
06-23 13:52:00.877 10873-10873/es.infaplic.gibmov W/System.err:     at android.support.design.widget.TextInputLayout.<init>(TextInputLayout.java:106)
06-23 13:52:00.877 10873-10873/es.infaplic.gibmov W/System.err:     ... 57 more

进行一些研究,我发现它可能与Android API&lt; 21处理样式和主题的方式有关,特别是你不能使用颜色的attrs。这是涉及的文件:

attrs.xml:     

<!-- Declare custom theme attributes that allow changing which styles are
     used for button bars depending on the API level.
     ?android:attr/buttonBarStyle is new as of API 11 so this is
     necessary to support previous API levels. -->
<declare-styleable name="ButtonBarContainerTheme">
    <attr name="metaButtonBarStyle" format="reference" />
    <attr name="metaButtonBarButtonStyle" format="reference" />
</declare-styleable>

styles_appthemes.xml:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

<style name="Theme.DoNotDim" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:backgroundDimEnabled">false</item>
</style>

<style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowBackground">@null</item>
    <!--<item name="metaButtonBarStyle">@style/ButtonBar</item>-->
    <!--<item name="metaButtonBarButtonStyle">@style/ButtonBarButton</item>-->
</style>

<style name="ButtonBar">
    <item name="android:paddingLeft">2dp</item>
    <item name="android:paddingTop">5dp</item>
    <item name="android:paddingRight">2dp</item>
    <item name="android:paddingBottom">0dp</item>
    <item name="android:background">@android:drawable/bottom_bar</item>
</style>

<style name="ButtonBarButton" />

<style name="AutoCompleteTextViewAppTheme" parent="android:Widget.Holo.Light.AutoCompleteTextView">
  <item name="android:dropDownSelector">@drawable/apptheme_list_selector_holo_light</item>
    <item name="android:background">@drawable/apptheme_edit_text_holo_light</item>
</style>

<style name="ButtonAppTheme" parent="android:Widget.Holo.Light.Button">
  <item name="android:background">@drawable/apptheme_btn_default_holo_light</item>
 </style>

 <style name="ImageButtonAppTheme" parent="android:Widget.Holo.Light.ImageButton">
  <item name="android:background">@drawable/apptheme_btn_default_holo_light</item>
</style>

   <style name="SpinnerAppTheme" parent="android:Widget.Holo.Light.Spinner">
  <item name="android:background">@drawable/apptheme_spinner_background_holo_light</item>
  <item name="android:dropDownSelector">@drawable/apptheme_list_selector_holo_light</item>
</style>

 <style name="TabAppTheme">
  <item name="android:gravity">center_horizontal</item>
  <item name="android:paddingLeft">16dip</item>
  <item name="android:paddingRight">16dip</item>
  <item name="android:background">@drawable/apptheme_tab_indicator_holo</item>
  <item name="android:layout_width">0dip</item>
  <item name="android:layout_weight">1</item>
  <item name="android:minWidth">80dip</item>
</style>

<style name="TabTextAppTheme">
  <item name="android:textColor">#000000</item>
  <item name="android:textSize">12sp</item>
  <item name="android:textStyle">bold</item>
  <!--&lt;!&ndash; v14 <item name="android:textAllCaps">true</item> -->
  <item name="android:ellipsize">marquee</item>
  <item name="android:maxLines">2</item>
  <item name="android:maxWidth">180dip</item>
 </style>

 <style name="ProgressBarAppTheme" parent="android:Widget.Holo.Light.ProgressBar.Horizontal">
  <item name="android:progressDrawable">@drawable/apptheme_progress_horizontal_holo_light</item>
  <item name="android:indeterminateDrawable">@drawable/apptheme_progress_indeterminate_horizontal_holo_light</item>
 </style>

  <style name="SeekBarAppTheme" parent="android:Widget.Holo.Light.SeekBar">
  <item name="android:progressDrawable">@drawable/apptheme_scrubber_progress_horizontal_holo_light</item>
  <item name="android:indeterminateDrawable">@drawable/apptheme_scrubber_progress_horizontal_holo_light</item>
  <item name="android:thumb">@drawable/apptheme_scrubber_control_selector_holo_light</item>
 </style>

 <style name="RatingBarAppTheme" parent="android:Widget.Holo.Light.RatingBar">
  <item name="android:progressDrawable">@drawable/apptheme_ratingbar_full_holo_light</item>
  <item name="android:indeterminateDrawable">@drawable/apptheme_ratingbar_full_holo_light</item>
 </style>

  <style name="RatingBarBigAppTheme" parent="android:Widget.Holo.Light.RatingBar.Indicator">
  <item name="android:progressDrawable">@drawable/apptheme_ratingbar_holo_light</item>
  <item name="android:indeterminateDrawable">@drawable/apptheme_ratingbar_holo_light</item>
 </style>

  <style name="RatingBarSmallAppTheme" parent="android:Widget.Holo.Light.RatingBar.Small">
  <item name="android:progressDrawable">@drawable/apptheme_ratingbar_small_holo_light</item>
  <item name="android:indeterminateDrawable">@drawable/apptheme_ratingbar_small_holo_light</item>
 </style>

 <style name="ToggleAppTheme" parent="android:Widget.Holo.Light.Button.Toggle">
  <item name="android:background">@drawable/apptheme_btn_toggle_holo_light</item>
  </style>-->

</resources>

这些文件都是继承的代码,所以我不太了解它们。我的问题是......我应该寻找什么来解决这个错误?知道哪里可能是错误?

谢谢。

0 个答案:

没有答案