在设计支持库NavigationView中,是否可以使标题栏固定不动?
这样做可以实现期望的效果(虽然有点hack),但当菜单项在标题下方时,仍然可以点击它们。有没有什么好的解决方法?
<android.support.design.widget.NavigationView
android:id="@+id/nav_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/nav_drawer"
style="@style/navigation_view_drawer"
/>
编辑:
我迄今为止的尝试导致了这个结果
重写 NavigationView 小部件并添加一个新方法:
public class CustomNavigationView extends NavigationView {
public CustomNavigationView(Context context) {
super(context);
}
public CustomNavigationView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomNavigationView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
// Inflates header as a child of NavigationView, on top of the normal menu
public void createHeader(int res) {
LayoutInflater inflater = LayoutInflater.from(getContext());;
View view = inflater.inflate(res, this, false);
addView(view);
}
然后将以下内容添加到活动的onCreate中:
CustomNavigationView navigationView = (CustomNavigationView) findViewById(R.id.your_navigation_view);
navigationView.createHeader(R.layout.your_header);
这样做可以实现期望的效果(虽然有点hack),但当菜单项在标题下方时,仍然可以点击它们。有没有什么好的解决方法?