标签: android-drawer

CoordinatorLayout + AppBarLayout + NavigationDrawer

CoordinatorLayout与a AppBarLayout和a 组合时,我有一个布局问题NavigationDrawer.

问题是,NavigationDrawer及其内容隐藏在工具栏后面.我已经做了很多研究并尝试了很多重组,但没有一个"解决方案"解决了我的问题.

可以在这个小小的Webm视频中找到演示:https://www.dropbox.com/s/i5zfc2x2ts2fws7/navigation_drawer_stackoverflow32523188.webm ? dl =0

基本风格是Theme.AppCompat.Light.NoActionBar.

我的activity_overview.xml如下所示:

<?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/overview_coordinator_layout"
    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: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"
            android:background="?attr/colorPrimaryDark"
            app:layout_scrollFlags="enterAlways|scroll" />


    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        android:focusableInTouchMode="true">

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/lorem_ipsum_long" />
        </android.support.v4.widget.NestedScrollView>

        <android.support.design.widget.NavigationView
            android:id="@+id/nvView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@android:color/white"
            app:headerLayout="@layout/nav_header"
            app:menu="@menu/navigationdrawer_main" />

    </android.support.v4.widget.DrawerLayout>


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/overview_floating_action_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"

        android:clickable="true"
        android:src="@drawable/ic_add"
        app:layout_anchor="@id/overview_coordinator_layout"
        app:layout_anchorGravity="bottom|right|end"
        app:layout_behavior="@string/fab_onscroll_behavior" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-coordinatorlayout android-appbarlayout android-drawer

59
推荐指数
2
解决办法
3万
查看次数

如何从android.support.v4.widget.DrawerLayout的Material Design guide启用或伪造迷你变体?

如何从" 材料设计"指南中启用"迷你变体" - 以便仅在其关闭状态下显示抽屉图标?

迷你变种

作为我的问题的简单测试项目,我采用了Google着名的导航抽屉示例 - 然后在右侧添加了第二个抽屉,并在两侧添加了ListView条目的图标:

截图

截图

请告知如何激活(或者假冒?)"迷你变体抽屉" - 以便在上面的屏幕截图的右侧只能看到音乐符号.

这是我的布局文件activity_main.xml:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout 
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.Toolbar 
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <ImageView 
            android:src="@drawable/ic_music_note_black_24dp"
            android:onClick="openActions"
            android:layout_gravity="right"
            android:padding="16dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        </android.support.v7.widget.Toolbar>

        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice" />

    <ListView
        android:id="@+id/right_drawer"
        android:layout_width="160dp"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:choiceMode="singleChoice" />

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

MainActivity.java使用它:

public class MainActivity extends AppCompatActivity {
    private Toolbar mToolbar;
    private DrawerLayout mDrawerLayout;
    private ListView …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-navigation material-design android-drawer

24
推荐指数
1
解决办法
4578
查看次数

如何在android中的ExpandableListView中添加三级ListView

我想在ExpandableListView中添加一个级别.当前ExpandableListView是两个级别如何添加一个级别.我是android开发新手请帮帮我.提前致谢!

我的MainActivity.java:-

 private Toolbar mToolbar;
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;

//   private FragmentDrawer drawerFragment;
ArrayList<String> arraylist1,arraylist2,arraylist3,arrayList4,arrayList5;
int cnt = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);

    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    expListView = (ExpandableListView) findViewById(R.id.lvExp);

    // preparing list data
    prepareListData();

    listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);

    // setting list adapter
    expListView.setAdapter(listAdapter);

   /*      drawerFragment = (FragmentDrawer)
            getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
    drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
    drawerFragment.setDrawerListener(this);*/
    // display the first navigation drawer view on app launch
  //      displayView(0); …
Run Code Online (Sandbox Code Playgroud)

java android android-layout android-listview android-drawer

14
推荐指数
3
解决办法
2万
查看次数

如何在DrawerLayout和NavigationView中使用自定义字体

我想使用Android DrawerLayoutNavigationView菜单,但我不知道如何让菜单项使用自定义字体.有没有人成功实施?

android android-fonts android-menu android-typeface android-drawer

6
推荐指数
1
解决办法
6993
查看次数

Android Jetpack 导航 - 如何从抽屉菜单项导航到嵌套导航图

我很好奇如何使用 Android Jetpack 中的导航图从抽屉布局中的菜单项导航到嵌套导航图。我知道幕后有一些魔法可以将菜单项与基于 Id 的片段链接起来,但我不知道如何将菜单项链接到嵌套导航图。

例如,我使用 Android Studio 附带的默认导航抽屉活动项目。我已将 mobile_navigation.xml 修改为以下内容:

<navigation 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/mobile_navigation"
    app:startDestination="@+id/nav_home">

    <fragment
        android:id="@+id/nav_home"
        android:name="com.example.testdrawer.ui.home.HomeFragment"
        android:label="@string/menu_home"
        tools:layout="@layout/fragment_home" />

    <include app:graph="@navigation/nested_navigation" />

    <fragment
        android:id="@+id/nav_tools"
        android:name="com.example.testdrawer.ui.tools.ToolsFragment"
        android:label="@string/menu_tools"
        tools:layout="@layout/fragment_tools" />

    <fragment
        android:id="@+id/nav_share"
        android:name="com.example.testdrawer.ui.share.ShareFragment"
        android:label="@string/menu_share"
        tools:layout="@layout/fragment_share" />

    <fragment
        android:id="@+id/nav_send"
        android:name="com.example.testdrawer.ui.send.SendFragment"
        android:label="@string/menu_send"
        tools:layout="@layout/fragment_send" />
</navigation>
Run Code Online (Sandbox Code Playgroud)

我还添加了一个名为nested_navigation.xml 的新导航图,如下所示:

<navigation 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/nested_navigation"
    app:startDestination="@+id/nav_gallery">

    <fragment
        android:id="@+id/nav_gallery"
        android:name="com.example.testdrawer.ui.gallery.GalleryFragment"
        android:label="@string/menu_gallery"
        tools:layout="@layout/fragment_gallery" />

    <fragment
        android:id="@+id/nav_slideshow"
        android:name="com.example.testdrawer.ui.slideshow.SlideshowFragment"
        android:label="@string/menu_slideshow"
        tools:layout="@layout/fragment_slideshow" />

</navigation>
Run Code Online (Sandbox Code Playgroud)

假设我的菜单如下所示:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:showIn="navigation_view">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_home"
            android:icon="@drawable/ic_menu_camera"
            android:title="@string/menu_home" />
        <item …
Run Code Online (Sandbox Code Playgroud)

android android-navigation android-drawer android-jetpack android-jetpack-navigation

6
推荐指数
1
解决办法
714
查看次数

Android 带抽屉的 Google 搜索栏

我的应用程序目前是使用单一活动方法实现的(使用具有一个主要活动和多个片段的导航架构组件)。我目前正在使用带抽屉的工具栏。

我的应用程序目前看起来像这样:

在此输入图像描述

然而,在现代谷歌应用程序(谷歌照片、gmail 等)中,谷歌实现了一种使用搜索字段进行导航的新方法,其中包含一个已实现的抽屉,如下所示:

在此输入图像描述

我想用搜索栏和抽屉菜单替换这个工具栏,就像 Google 应用程序一样。

有人可以帮助我编写一些关于如何实现此目标的代码吗?

我的主要活动如下:

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

<androidx.drawerlayout.widget.DrawerLayout
    android:id="@+id/Drawer_Main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.main.main.MainActivity">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <com.google.android.material.appbar.MaterialToolbar
            android:id="@+id/Toolbar_Main"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary">

            <TextView
                android:id="@+id/Toolbar_Title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
            android:text="@string/app_name"
                style="@style/Locky.Toolbar.TitleText" />

        </com.google.android.material.appbar.MaterialToolbar>

        <androidx.core.widget.NestedScrollView
            android:id="@+id/Nested_Scroll"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="?attr/actionBarSize"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <fragment
                android:id="@+id/Navigation_Host"
                android:name="androidx.navigation.fragment.NavHostFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:defaultNavHost="true"
                app:navGraph="@navigation/navigation_drawer_main" />

        </androidx.core.widget.NestedScrollView>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:orientation="vertical">

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/FAB_Account"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginEnd="16dp"
            android:layout_marginStart="16dp"
            android:visibility="invisible"
            app:srcCompat="@drawable/ic_account"
            style="@style/Locky.FloatingActionButton.Mini" />

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/FAB_Card"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginEnd="16dp"
            android:layout_marginStart="16dp"
            android:visibility="invisible"
            app:srcCompat="@drawable/ic_credit_card"
            style="@style/Locky.FloatingActionButton.Mini" …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-search android-drawer android-architecture-navigation

6
推荐指数
1
解决办法
2492
查看次数

RTL上的Android NavigationView错误图标位置

我正在使用com.android.support:design:23.1.0,而且我也在android:supportsRtl="true"使用清单.

我正在尝试创建一个在RTLLTR语言上都能正常工作的抽屉.

但是RTL语言中的默认行为是错误的.

我怎么能解决这个问题?

tnx提前.

在此输入图像描述

在此输入图像描述

activity_main2.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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main2"
        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"
        app:headerLayout="@layout/nav_header_main2"
        app:menu="@menu/activity_main2_drawer"/>

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

nav_header_main2.xml:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="@dimen/nav_header_height"
              android:background="@drawable/side_nav_bar"
              android:paddingBottom="@dimen/activity_vertical_margin"
              android:paddingLeft="@dimen/activity_horizontal_margin"
              android:paddingRight="@dimen/activity_horizontal_margin"
              android:paddingTop="@dimen/activity_vertical_margin"
              android:theme="@style/ThemeOverlay.AppCompat.Dark"
              android:orientation="vertical"
              android:gravity="bottom">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:src="@android:drawable/sym_def_app_icon"
        android:id="@+id/imageView"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:text="Android Studio"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="android.studio@android.com"
        android:id="@+id/textView"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

activity_main2_drawer.xml:

<?xml …
Run Code Online (Sandbox Code Playgroud)

android android-menu android-design-library android-drawer

5
推荐指数
0
解决办法
632
查看次数

Android抽屉布局可能会产生空指针异常

我一直在我的代码中收到这个警告,我开始担心,因为我接近完成的最后期限.我的主要活动中有一个DrawerLayout,使用Android Studio自己的导航抽屉活动,但由于现在不推荐使用DrawerLayout setDrawerListener,因此必须对代码稍作更改.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Firebase reference to main application URL and 'today's' matches
    Firebase mainRef = new Firebase(cons.getFirebaseUrl());

    //DrawerLayout settings for the navigation drawer
    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.addDrawerListener(toggle);
    toggle.syncState();

    //Retrieve the navigation drawer and set it's listener for menu item presses
    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
Run Code Online (Sandbox Code Playgroud)

我收到了关于drawer.addDrawerListener(toggle)和的警告navigationView.setNavigationItemSelectedListener(this)

在我的代码中,我也在这个方法中接收它:

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if …
Run Code Online (Sandbox Code Playgroud)

android navigation-drawer android-navigation android-drawer

5
推荐指数
1
解决办法
1128
查看次数

Android Navigation Drawer Remains Highlighted

I am able to navigate from Activity1 to Activity2 via my navigation drawer.

But upon pressing the back button at activity2, the option remains highlighted.

My Code in activity1 is as followed

public boolean onNavigationItemSelected(MenuItem Item)
{
    int id = item.getItemId();

    if(id == R.id.activity2)
    {
        Intent goPage2 = new Intent(activity1.this, activity2.class);
        startActivity(goPage2);
    }
}
Run Code Online (Sandbox Code Playgroud)

there is no code in activity 2.

May I know what do I do to remove the highlight?

android android-navigation android-drawer

5
推荐指数
2
解决办法
2466
查看次数

更改菜单操作布局值?

navigationView.getHeaderView(0);我有一个导航抽屉,我可以通过访问和来更改字体、颜色等。

Menu m = navigationView.getMenu();
MenuItem mi = m.getItem(index);
Run Code Online (Sandbox Code Playgroud)

然后我就可以玩抽屉里的东西了。

但就我而言,我有一个文本视图,它是另一种布局:

<item
        android:id="@+id/nav_wallet"
        android:icon="@drawable/ic_balnce"
        android:title="@string/my_wallet"
        app:actionLayout="@layout/wallet_value"/>
Run Code Online (Sandbox Code Playgroud)

在我的 wallet_value 中,layout我有一个 textView,我需要更改其值,如下图所示:

在此输入图像描述

我怎样才能得到这个布局并改变它?

android android-layout android-menu android-drawer android-navigationview

3
推荐指数
1
解决办法
1919
查看次数