我正在关注this tutorial on hiding/showing toolbar when list is scrolling。
如果我使用源项目可以正常工作,但是当我尝试创建示例时,它将无法正常工作。
我在隐藏工具栏和选项卡时遇到问题。
这是我的主要活动。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/color_accent_pink"
app:layout_scrollFlags="scroll|enterAlways"
/>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabTextColor="@android:color/white"
app:tabSelectedTextColor="@android:color/white"
app:tabIndicatorColor="@android:color/white"
app:tabIndicatorHeight="6dp"
app:layout_scrollFlags="scroll|enterAlways"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
回收站视图
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" />
我的适配器
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder>
{
int mSize;
Context mContext;
LayoutInflater mLayoutInflater;
public MyAdapter(int mSize, Context context) {
this.mSize = mSize;
this.mContext = context;
this.mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = mLayoutInflater.inflate(R.layout.item_recyclerview,parent,false);
MyViewHolder myViewHolder = new MyViewHolder(v);
return myViewHolder;
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
holder.textView.setText("position: "+position);
}
@Override
public int getItemCount() {
return mSize;
}
public class MyViewHolder extends RecyclerView.ViewHolder{
public TextView textView;
public MyViewHolder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.textView);
}
}
}
这是我的Recycler View片段;
public class ListFragment extends Fragment {
protected RecyclerView mRecyclerView;
public int mSize;
public int getmSize() {
return mSize;
}
public void setmSize(int mSize) {
this.mSize = mSize;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.recycler_view,container,false);
Log.i("mSizeOnCreateView", String.valueOf(mSize));
mRecyclerView = (RecyclerView) v.findViewById(R.id.my_recycler_view);
mRecyclerView.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(getActivity());
llm.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(llm);
MyAdapter myAdapter = new MyAdapter(mSize,getActivity());
mRecyclerView.setAdapter(myAdapter);
return v;
}
}
最佳答案
问题是回收站视图的版本
与
compile 'com.android.support:recyclerview-v7:22.2.0'
一切都解决了。
关于android - 具有Material DesignSupport的Android不会隐藏工具栏,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31541683/