标签: navigation-drawer

Android NavigationDrawer和ViewPager作为其片段之一

我创建了一个SherlockFragmentActivity,它有三个ViewPager片段.但是现在我想在NavigationDrawer中使用这个Activity但是我很困惑如何做到这一点.Google+应用有这种实现,但我想知道如何实现这一目标.

NavigationDrawer将具有以下UI元素:

  1. FragmentActivity(包含三个片段作为ViewPager)
  2. 第二片段
  3. 第三片段

使用导航抽屉是否可以进行这种布局如果是,我应该怎么做.如果没有,我应该怎么做才能在我的应用程序中实现这种导航.

android android-fragments android-viewpager navigation-drawer

0
推荐指数
1
解决办法
5243
查看次数

阻止在主页按钮上打开NavigationDrawer单击

我的主要活动有一个NavigationDrawer,在一个实例中我显示了一个片段,"汉堡菜单"变成了一个箭头.

当使用此片段显示该片段时,我禁用了通过滑动打开抽屉的功能

mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
Run Code Online (Sandbox Code Playgroud)

它工作正常但现在问题是用户仍然可以通过单击主页按钮"箭头"打开抽屉.我希望箭头作为后退按钮而不打开抽屉,这样我怎么能阻止抽屉打开?

android navigation-drawer

0
推荐指数
1
解决办法
1453
查看次数

如何实现从右侧打开抽屉菜单

我按照本教程创建了一个导航抽屉

但我需要的是,我需要从右侧打开相同的抽屉菜单。有谁知道如何实现这一目标?

以下是我的 xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<LinearLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical"
    >
    <include
        android:id="@+id/toolbar"
        layout="@layout/tool_bar"
    />
    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </FrameLayout>

</LinearLayout>
<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:layout_gravity="right"
    app:headerLayout="@layout/header"
    app:menu="@menu/drawer"
    />
Run Code Online (Sandbox Code Playgroud)

并在代码中

  // Initializing Drawer Layout and ActionBarToggle
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this,drawerLayout,toolbar,R.string.openDrawer, R.string.closeDrawer){

        @Override
        public void onDrawerClosed(View drawerView) {
            // Code here will be triggered once the drawer closes as we dont want anything to happen so we …
Run Code Online (Sandbox Code Playgroud)

android navigation-drawer drawerlayout

0
推荐指数
1
解决办法
2万
查看次数

android.support.v4.app.FragmentTransaction 无法转换为片段管理器

我正在尝试navigation drawer在我的应用程序中创建。在我的一个navigation drawer itemView我希望它有2个tabsswipe view功能。我可以单独创建它们,但是当我尝试在 1 中执行时,出现错误。

MainActivity // 用于导航抽屉项

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

private void selectItem(int position) {

        Fragment fragment = null;

        switch (position) {
            case 0:
                fragment=new Information();
                break;
            case 1:

                fragment=new Claims1();
                Bundle bundle=new Bundle();
                bundle.putLong("ab",WorkDetailsTable.ab);
                fragment.setArguments(bundle);
                break;

            case 2:
                fragment=new ViewView();
                break;

            default:
                break;
        }

        if (fragment != null) {
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); 

            mDrawerList.setItemChecked(position, true);
            mDrawerList.setSelection(position);
            setTitle(mNavigationDrawerItemTitles[position]);
            mDrawerLayout.closeDrawer(mDrawerList);

        } else {
            Log.e("MainActivity", "Error …
Run Code Online (Sandbox Code Playgroud)

tabs android swipeview navigation-drawer

0
推荐指数
1
解决办法
4398
查看次数

使用带有活动或碎片的导航抽屉?

我有侧边栏导航抽屉布局的Android应用程序,我正在实现一个简单的短信应用程序的功能.

我的问题是,如何在活动之间重用导航抽屉代码.每个示例都使用在单击导航抽屉菜单中的项目后在某些主视图中显示的片段.如果我发布新活动并希望拥有与原始活动相同的侧边菜单,该怎么办?

谷歌是否有官方建议如何实施?

对我来说问题是,为了成为Android上的默认短信应用,你必须有一些处理某些意图的特殊活动.

我应该完全转储活动并使用碎片实现一切吗?

谢谢

android android-layout android-fragments android-activity navigation-drawer

0
推荐指数
1
解决办法
950
查看次数

Android汉堡菜单和后退箭头

我想在我的MainActivity上为我的用户提供汉堡包和后箭头的属性导航.

当我只有一个片段设置汉堡包时,但如果我在MainActivity上添加了更多片段,请设置后退箭头.

我该如何实现?

这是我的实施......

public class MainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener {

private Toolbar toolbar;
private DrawerLayout drawer;
private NavigationView navigationView;

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

    setSupportActionBar(toolbar);

    final ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    navigationView.setNavigationItemSelectedListener(this);

    //TODO: Insert back arrow button if have more than one fragment on backstack
    /*getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            int stackHeight = getSupportFragmentManager().getBackStackEntryCount();
            if (stackHeight > 0) {
                if (getSupportActionBar() != null) {
                    getSupportActionBar().setHomeButtonEnabled(true); …
Run Code Online (Sandbox Code Playgroud)

android navigation-drawer android-navigation android-toolbar

0
推荐指数
1
解决办法
3898
查看次数

Android导航视图自定义宽度

有没有办法给Android导航视图自定义宽度,我正在使用Android工作室.我通过谷歌搜索尝试了不同的方式,但没有运气,请帮助我.

在处理不同屏幕尺寸时,最佳做法是提供自定义宽度吗?

这是我的xml代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/top_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".Dashbored">

<include
    android:id="@+id/tool_bar"
    layout="@layout/tool_bar">

</include>


<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/tool_bar"
    android:elevation="7dp"
    android:fitsSystemWindows="true"
    tools:openDrawer="end">


    <LinearLayout
        android:id="@+id/linear_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">


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

            <include layout="@layout/f_home_screen" />

        </FrameLayout>


    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:background="#0284fe"
        android:fitsSystemWindows="true">

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

            <include
                android:id="@+id/navheader"
                layout="@layout/nav_header" />

            <ListView
                android:id="@+id/lst_menu_items"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:divider="@null"
                android:dividerHeight="0dp"

                />
        </LinearLayout>

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


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

谢谢

xml android navigation-drawer

0
推荐指数
1
解决办法
3932
查看次数

按下后从片段转到主活动(导航视图)

尝试了很多方法,但没有一个完美地工作。我想从导航视图中设置的片段中获取主要活动。我试过

@Override
public void onBackPressed() {
    startActivity(new Intent(this, MainActivity.class));
}
Run Code Online (Sandbox Code Playgroud)

但它不会正常工作。我希望它就像当我处于零散的活动中时它返回到主活动,而再次单击返回时它退出(我已经这样做了),当按下返回时帮助我回到主活动

主活动.java

public class MainActivity extends AppCompatActivity {

private static final int PERMISSION_REQUEST_CODE = 1000 ;

private static final String TAG = "MainActivity";

private AdView mAdView;

ImageView imageView;


RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;

List<Item> items;
CustomAdapter adapter;
private long backpressedtime;




@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode)
    {
        case PERMISSION_REQUEST_CODE:
        {
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
                Toast.makeText(this, "Permission …
Run Code Online (Sandbox Code Playgroud)

android back android-fragments navigation-drawer navigationview

0
推荐指数
1
解决办法
901
查看次数

Flutter:如何将 Drawer Header 宽度设置为最大值?

我正在我的应用程序中添加抽屉,并遵循官方指南。我想将 Drawer 分为三个部分:

  1. 抽屉头(顶部)

  2. 部分项目

  3. 设置(底部)

如果我ListView是其直接子代,Drawer则它可以正常工作,但我无法在底部添加“设置”部分。我发现了这个,它符合我的要求,但DrawerHeader不占用最大宽度。

这是我的代码

      Drawer(
            elevation: 1.5,
            child: Column(children: <Widget>[
              DrawerHeader(
                  decoration: BoxDecoration(
                color: Colors.redAccent,
              )),
              Expanded(
                  child: ListView(
                padding: EdgeInsets.zero,
                children: <Widget>[
                  //list tiles
                ],
              )),
              Container(
                color: Colors.black,
                width: double.infinity,
                height: 0.1,
              ),
              Container(
                  padding: EdgeInsets.all(10),
                  height: 100,
                  child: Text("V1.0.0",style: TextStyle(fontWeight: FontWeight.bold),)),
            ])),
Run Code Online (Sandbox Code Playgroud)

默认情况下,抽屉标题宽度不是最大的。它根据内容大小进行调整,如果我增加字体大小或在左侧和右侧添加填充,则需要更多的宽度。

检查下图以供参考:

在此处输入图片说明

navigation-drawer drawerlayout flutter flutter-layout

0
推荐指数
1
解决办法
6123
查看次数

NavigationView onNavigationItemSelected 不起作用

我一直试图让我的导航抽屉事件正常工作,但你猜对了,它不会。因为每次我点击导航抽屉中的一个项目时都不会触发任何东西。我也在这里尝试了一些帮助,但无济于事。

活动_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@drawable/sidebar_bg_fainted"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</androidx.drawerlayout.widget.DrawerLayout>

Run Code Online (Sandbox Code Playgroud)

主活动.java

package com.example.airtimeflip;

import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import android.view.MenuItem;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.core.view.GravityCompat;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.google.android.material.navigation.NavigationView;

import androidx.drawerlayout.widget.DrawerLayout;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.RecyclerView;

import android.view.Menu;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener …
Run Code Online (Sandbox Code Playgroud)

android android-studio navigation-drawer android-navigationview

0
推荐指数
1
解决办法
2895
查看次数