在NavigationView标题中更新我的标题文本和图像后,我在NavigationView标题中获得重复值.
这是我的代码部分
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
boolean doubleBackToExitPressedOnce = false;
SQLiteHelper dbHelper;
String setName, setMail;
AlertDialog.Builder builder, builder_verify;
public static int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
dbHelper = new SQLiteHelper(getApplicationContext());
builder_verify = new AlertDialog.Builder(this);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
View hView = navigationView.inflateHeaderView(R.layout.nav_header_main);
ImageView iv = …Run Code Online (Sandbox Code Playgroud) 我在DrawerLayout中使用NavigationView为我的应用程序导航菜单这里是xml:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:foreground="?android:attr/selectableItemBackground"
android:theme="@style/NavigationDrawerStyle"
app:headerLayout="@layout/nav_header_main"
app:itemIconTint="@color/textColor"
app:itemTextColor="@color/textColor"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
问题:我甚至没有足够的项目滚动,但我在尝试滚动时看到这个效果,我想禁用此效果,谢谢.
滚动效果
更新
尝试两者:
android:overScrollMode "never" in NavigationView
Run Code Online (Sandbox Code Playgroud)
和
navigationView.setVerticalFadingEdgeEnabled(false);
Run Code Online (Sandbox Code Playgroud)
没用.
我正在调用以下方法onCreate():
public void setupDrawerLayout() {
drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolBar, R.string.drawer_open, R.string.drawer_close);
drawerLayout.setDrawerListener(drawerToggle);
drawerToggle.syncState();
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
Run Code Online (Sandbox Code Playgroud) android navigation-drawer material-design android-navigationview
我的问题:
我想在导航抽屉中添加可拖动图标.
抽屉打开时,此图标与导航抽屉列表视图相结合.
看到类似这样的,
我试过的,
我在StackOverflow中搜索过类似的问题,
但所有答案都建议第三方图书馆.
我的问题
1.可以在导航抽屉中添加可拖动图标吗?
android android-custom-view navigation-drawer android-navigation android-navigationview
在我的应用程序中,我想添加N级可扩展Menu,NavigationView如Paytm app截图如下.我试图添加ExpandableListView但不明白如何在NavigationView使用中添加N级可扩展菜单ExpandableListView
如果有人知道如何做到这一点,请帮助我.
我尝试从这个参考链接但不能做/sf/answers/2218998281/
我一直在尝试在状态栏下面绘制NavigationView标题,但它仍然位于状态栏后面.
我已经android:fitsSystemWindows="true"为我的DrawerLayout和我的NavigationView 设置了属性,但无济于事.
这是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/activity_dashboard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways|snap">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
android navigation-drawer navigationview android-navigationview
通过使用
<item
android:id="@+id/nav_ad"
android:title="@null"
app:actionLayout="@layout/sidebar_ad" />
Run Code Online (Sandbox Code Playgroud)
我可以使用自定义布局并在NavigationView中创建原生广告.但是,列表项的高度似乎固定为相同的值,这意味着无法单独更改特定项的高度.
View view = mNavView.getMenu().findItem(R.id.nav_ad).getActionView()确实返回我创建的自定义视图,但view.getParent()返回null,这意味着无法获取容器对其的引用setMinimumHeight().
我甚至想过使用反射来破解NavigationMenuAdapter,但由于它是一个私有的内部类,我甚至不知道从哪里开始.
是使用另一个抽屉库/写我自己的抽屉视图唯一的方法去?
android admob navigationview android-support-design android-navigationview
我使用android导航体系结构组件实现了对LoginFragment的条件导航。我现在面临的问题是,我想隐藏工具栏上的向上按钮,并在用户未登录时禁用任何应用内导航。
我希望能够通过一种活动的方法来实现这一点,其中“活动”像在android sunflower演示中一样设置应用内导航UI和navController,并且导航目标是“片段”。
我实现了此处描述的条件导航: 导航体系结构组件-登录屏幕
如何使用导航体系结构组件正确实现在登录屏幕上隐藏导航和向上按钮?
android up-button android-navigationview android-architecture-components android-architecture-navigation
我正在尝试将使用png资源的Android应用程序迁移到图标字体.我可以使用列表视图在导航抽屉中成功使用它.但是我无法在导航视图中使用它,只需在菜单的xml文件中指定它即可.
这是我尝试时得到的 Navigation Drawer
我不知道如何使用图标字体navigation view来获取那些标记的图标.
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_apple"
android:icon="@drawable/ic_menu_apple"
android:title="Apple" />
<item
android:id="@+id/nav_chrome"
android:icon="@drawable/ic_menu_chrome"
android:title="Orange" />
<item
android:id="@+id/nav_left"
android:icon="@drawable/ic_menu_left"
android:title="Grapes" />
</group>
Run Code Online (Sandbox Code Playgroud)
如何在此菜单中使用图标字体设置这些图标?
android font-awesome icon-fonts navigationview android-navigationview
如何为 NavigationView 中的项目设置填充。我需要为项目设置 paddingLeft,因为我已经删除了图标。我尝试过的是这个,但它不起作用:
<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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
app:headerLayout="@layout/nav_header_navigation_drawer"
app:itemBackground="@drawable/selected_background"
app:itemTextAppearance="@style/Drawer"
app:menu="@menu/activity_navigation_drawer_drawer" />
Run Code Online (Sandbox Code Playgroud)
我的 Drawer.xml 文件样式:
<style name="Drawer">
<item name="android:listPreferredItemPaddingLeft">50dp</item>
<item name="android:textSize">30sp</item>
<item name="android:typeface">serif</item>
</style>
Run Code Online (Sandbox Code Playgroud) android navigationview android-navigationview material-components material-components-android
我的问题是,当我尝试使用底部导航更改片段时,它会起作用,但在一种情况下除外。我有 5 个片段,当我进入第 3 个片段并进入第 5 个片段后,第 5 个片段的图标 don\xc2\xb4t 改变了它的颜色。之后,当我进行另一次导航时,应用程序崩溃并给出下一个错误:
\njava.lang.IndexOutOfBoundsException: fromIndex = -1\n at java.util.ArrayList.subListRangeCheck(ArrayList.java:1014)\n at java.util.ArrayList.subList(ArrayList.java:1008)\n at androidx.navigation.fragment.FragmentNavigator.popBackStack(FragmentNavigator.kt:80)\n at androidx.navigation.NavController.popBackStackInternal(NavController.kt:275)\n at androidx.navigation.NavController.popBackStackInternal(NavController.kt:558)\n at androidx.navigation.NavController.navigate(NavController.kt:1682)\n at androidx.navigation.NavController.navigate(NavController.kt:1541)\n at androidx.navigation.NavController.navigate(NavController.kt:1468)\n at androidx.navigation.ui.NavigationUI.onNavDestinationSelected(NavigationUI.kt:92)\n at androidx.navigation.ui.NavigationUI.setupWithNavController$lambda-6(NavigationUI.kt:602)\n at androidx.navigation.ui.NavigationUI.$r8$lambda$6wzEv9QqEZKdQFS1sQQy-bdQvgE(Unknown Source:0)\n at androidx.navigation.ui.NavigationUI$$ExternalSyntheticLambda2.onNavigationItemSelected(Unknown Source:2)\n at com.google.android.material.navigation.NavigationBarView$1.onMenuItemSelected(NavigationBarView.java:295)\n at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:834)\n at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)\n at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:985)\n at com.google.android.material.navigation.NavigationBarMenuView$1.onClick(NavigationBarMenuView.java:133)\n at android.view.View.performClick(View.java:7520)\n at android.view.View.performClickInternal(View.java:7489)\n at android.view.View.access$3600(View.java:826)\n at android.view.View$PerformClick.run(View.java:28555)\n at android.os.Handler.handleCallback(Handler.java:938)\n at android.os.Handler.dispatchMessage(Handler.java:99)\n at android.os.Looper.loop(Looper.java:233)\n at android.app.ActivityThread.main(ActivityThread.java:8010)\n at java.lang.reflect.Method.invoke(Native Method)\n at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)\n at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)\nRun Code Online (Sandbox Code Playgroud)\n但是,如果之前我单击了第 5 个片段并转到第 3 …
android android-navigation android-navigationview android-navigation-bar android-navigation-graph
android ×10
admob ×1
android-architecture-components ×1
android-architecture-navigation ×1
font-awesome ×1
icon-fonts ×1
material-components-android ×1
up-button ×1
xml ×1