1

アンドロイドで固定ミニナビ引き出しを作りたい。常にアイコンで表示され、拡張可能ではありません。アイコン付きAndroidビルドミニナビゲーションドロワー

何かのようなものhttps://github.com/mikepenz/MaterialDrawerミニ引き出し。 私は彼の図書館を使いましたが、それを修正する方法を理解できません。そのライブラリのドキュメントで

private Drawer result = null; 
private MiniDrawer miniResult = null; 


result = new DrawerBuilder() 
       .withActivity(this) 
       .withToolbar(toolbar) 
       .withTranslucentStatusBar(false) 
       .addDrawerItems(
         new PrimaryDrawerItem().withName("1").withIcon(FontAwesome.Icon.faw_home).withIdentifier(1), 
         new PrimaryDrawerItem().withName("2").withIcon(FontAwesome.Icon.faw_home).withBadge("22").withBadgeStyle(new BadgeStyle(Color.RED, Color.RED)).withIdentifier(2).withSelectable(false), 
          new DividerDrawerItem(), 
         new ToggleDrawerItem().withName("3").withIcon(FontAwesome.Icon.faw_home).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener) 
       ) // add the items we want to use with our Drawer 
       .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { 
        @Override 
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { 
         if (drawerItem instanceof Nameable) { 
          Toast.makeText(MainActivity.this, ((Nameable) drawerItem).getName().getText(MainActivity.this), Toast.LENGTH_SHORT).show(); 
         } 
         return false; 
        } 
       }) 
       .withGenerateMiniDrawer(true) 
       .withSavedInstance(savedInstanceState) 
       // build only the view of the Drawer (don't inflate it automatically in our layout which is done with .build()) 
       .buildView(); 


     miniResult = result.getMiniDrawer(); 
     View view = miniResult.build(this); 

答えて

1

を使用しようとしてみてくださいDrawerLayout)、をご使用の場合はMiniDrawerを使用し、それをView階層に追加します。

MiniDrawerは、通常DrawerBuilderで塗りつぶされています。これは、引き出しに追加された要素とやりとりするすべてのメソッドが付属しているためです。

ユースケースは特別なので、MiniDrawerだけの「すぐに使える」膨張はありません。

したがって、上記のMiniDrawerViewがあります。今すぐあなたのActivityに追加するだけです。

私はあなたのレイアウトは次のようになりますことをお勧めします。

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize"/> 
    <LinearLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/toolbar"> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
      <!-- Place your content here --> 
     </RelativeLayout> 
    </LinearLayout> 
</RelativeLayout> 

だからあなたのコードの中で、あなたが「コンテナ」

LinearLayout container = (LinearLayout) findViewById(R.id.container); 
container.addView(view, 0); //view is the view of your MiniDrawer 

ちょうどあなたのコードを改善し、不要なものを削除するを取得します。あなただけのミニ引き出しの幅が大きすぎるMiniDrawer

+0

を使用している場合、それらは必要ないとあなたが

.withToolbar(toolbar) .withTranslucentStatusBar(false) 

を削除することができ、それを手動でカスタマイズすることが離れて存在しているのですか?あなたのコメントをありがとう、本当に感謝しています。 – MrG

+0

だから、あなたは '72dp'よりも少ない必要がありますか? 'MiniDrawer'は全て' 72dp'用に最適化され定義されていますが、それを変更することは可能ですが、もう少し作業が必要になります – mikepenz

+0

それで今はうまくいきます。だからあなたは答えを受け入れるかもしれないし、 'MiniDrawer'の幅を変更する方法に関する新しい質問を開くと、後日、新しい質問の詳細な回答が追加されます。他人にも役立ちます – mikepenz

0

開発者はあなたがlock the drawerをできることを述べた:

は、ここに私のコードです。あなたはそれを試して、それが開けないのを見ることができますか?

result = new DrawerBuilder()... 
... 
//get the DrawerLayout from the Drawer 
DrawerLayout drawerLayout = result.getDrawerLayout(); 
//do whatever you want with the Drawer. Like locking it. 
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); 

またLOCK_MODE_CLOSEDが仕事と私たちは何が起こるか知らせていない場合hereを定義し、他のロック・モードを試してみてください!

0

あなたがこの方法のように、あなたの引き出しのためのビューを作成することができ、ActionsContentView

<shared.ui.actionscontentview.ActionsContentView 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@id/divider" 
     app:actions_layout="@layout/actions" 
     app:actions_spacing="0dp" 
     app:content_layout="@layout/content" 
     app:shadow_drawable="@drawable/shadow" 
     app:shadow_width="8dip" 
     app:spacing="64dip" 
     app:spacing_type="right_offset" /> 

を使用するか、「通常の」引き出し(経由が常にある通常の使用のとおりPartial SlidingPaneLayout

関連する問題