我想使用navigation drawer
设置NavigationView
。项目不可见但是当我们点击空白区域时,特定项目点击代码正在执行。看起来物品看不见但可点击。
我尝试使用背景颜色,但它似乎没有效果。
任何帮助都将不胜感激。
home.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:fitsSystemWindows="true"
tools:context=".Home.HomeActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar" />
<!-- Main Content -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/White">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:orientation="vertical"
android:weightSum="1">
<android.support.design.widget.NavigationView
android:id="@+id/NavigationView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="start"
android:layout_weight="1"
android:background="@color/White"
android:fitsSystemWindows="true"
android:scrollbars="none"
app:elevation="0dp"
app:headerLayout="@layout/navigation_header"
app:itemIconTint="@color/YellowOrange"
app:itemTextColor="@color/Black"
app:menu="@menu/nav_menu" />
<com.squawkinit.orionfreightelite.customview.CustomTextView
android:id="@+id/tvAppVersion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dp"
android:textColor="@color/Black"
android:textSize="14sp" />
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
nav_menu.xml(菜单)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item
android:id="@+id/dashboardMenu"
android:title="@string/dashboard_menu" />
<item
android:id="@+id/eLogMenu"
android:title="@string/eLog_menu" />
<item
android:id="@+id/emergencyMenu"
android:title="@string/emergency_menu" />
<item
android:id="@+id/syncMenu"
android:actionLayout="@layout/sync_status"
android:title="@string/sync_menu" />
<item
android:id="@+id/manifestMenu"
android:title="@string/manifest_menu" />
<item
android:id="@+id/groupMessagingMenu"
android:title="@string/group_messaging_menu" />
<item
android:id="@+id/helpMenu"
android:title="@string/help_menu" />
<item
android:id="@+id/logoutMenu"
android:title="@string/logout_menu" />
</group>
navigation_header.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White">
<LinearLayout
android:id="@+id/navigationHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/accent_material_dark"
android:orientation="vertical">
<ImageView
android:id="@+id/ivDrawerIcon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/orion_elite_logo" />
<com.squawkinit.orionfreightelite.customview.CustomTextView
android:id="@+id/tvDrawerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColor="@color/White"
android:textSize="16sp" />
<com.squawkinit.orionfreightelite.customview.CustomTextView
android:id="@+id/tvDrawerMobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="5dp"
android:textColor="@color/LightWhite"
android:textSize="14sp" />
</LinearLayout>
CustomTextView
public class CustomTextView extends TextView {
public CustomTextView(Context context) {
super(context);
// TODO Auto-generated constructor stub
if (!isInEditMode())
setCustomFont(context);
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
if (!isInEditMode())
setCustomFont(context);
}
public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
if (!isInEditMode())
setCustomFont(context);
}
public void setCustomFont(Context ctx) {
Typeface tf = Typeface.createFromAsset(ctx.getAssets(),
"fonts/DroidSerif_Regular.ttf");
setTypeface(tf);
}
}
主题
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/Black</item>
<item name="android:textColorPrimary">@color/Black</item>
<item name="android:textColorSecondary">@color/Black</item>
<item name="colorAccent">@color/Orange</item>
<item name="textColor">@color/Black</item>
</style>
答案 0 :(得分:6)
最后!!我做到了。
在navigation_header
根布局高度应为wrap_content
而不是match_parent
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" // This should be wrap_content
android:background="@color/White">
<LinearLayout
android:id="@+id/navigationHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/accent_material_dark"
android:orientation="vertical">
<ImageView
android:id="@+id/ivDrawerIcon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/orion_elite_logo" />
<com.squawkinit.orionfreightelite.customview.CustomTextView
android:id="@+id/tvDrawerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColor="@color/White"
android:textSize="16sp" />
<com.squawkinit.orionfreightelite.customview.CustomTextView
android:id="@+id/tvDrawerMobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="5dp"
android:textColor="@color/LightWhite"
android:textSize="14sp" />
答案 1 :(得分:1)
我无法100%重现,因为我没有自定义类,但是嵌套的NavigationView给了我一个偏移到顶部的菜单。
那么如何删除外部NavigationView呢?
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:fitsSystemWindows="true"
tools:context=".Home.HomeActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar" />
<!-- Main Content -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White"
android:orientation="vertical"
android:weightSum="1">
<android.support.design.widget.NavigationView
android:id="@+id/NavigationView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="start"
android:layout_weight="1"
android:background="@color/White"
android:fitsSystemWindows="true"
android:scrollbars="none"
app:elevation="0dp"
app:headerLayout="@layout/navigation_header"
app:itemIconTint="@color/YellowOrange"
app:itemTextColor="@color/Black"
app:menu="@menu/nav_menu" />
<com.squawkinit.orionfreightelite.customview.CustomTextView
android:id="@+id/tvAppVersion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dp"
android:textColor="@color/Black"
android:textSize="14sp" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>