gpt4 book ai didi

android - 如何启用或伪造来自 android.support.v4.widget.DrawerLayout 的 Material Design 指南的迷你变体?

转载 作者:IT老高 更新时间:2023-10-28 22:18:21 26 4
gpt4 key购买 nike

如何启用 Material Design guide 中的“迷你变体” - 所以只有抽屉图标显示在关闭状态?

mini variant

作为 a simple test project对于我的问题,我采用了著名的 Navigation Drawer Example by Google - 然后在右侧添加第二个Drawer和两侧ListView条目的图标:

screenshot

screenshot

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

这是我的布局文件 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>

还有 MainActivity.java使用它:

public class MainActivity extends AppCompatActivity {
private Toolbar mToolbar;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ListView mActionList;
private ActionBarDrawerToggle mDrawerToggle;

private String[] mPlanetTitles;
private String[] mActions;
private int[] mIcons;

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

mPlanetTitles = getResources().getStringArray(R.array.planets_array);
mActions = getResources().getStringArray(R.array.music_actions);

TypedArray ta = getResources().obtainTypedArray(R.array.music_icons);
mIcons = new int[ta.length()];
for (int i = 0; i < mIcons.length; i++)
mIcons[i] = ta.getResourceId(i, R.drawable.ic_menu_black_24dp);
ta.recycle();

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

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mActionList = (ListView) findViewById(R.id.right_drawer);

mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, mPlanetTitles) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView view = (TextView) super.getView(position, convertView, parent);
view.setCompoundDrawablePadding(24);
view.setCompoundDrawablesWithIntrinsicBounds(
R.drawable.ic_stars_white_24dp, 0, 0, 0);
return view;
}
});

mActionList.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, mActions) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView view = (TextView) super.getView(position, convertView, parent);
view.setCompoundDrawablePadding(24);
view.setCompoundDrawablesWithIntrinsicBounds(mIcons[position], 0, 0, 0);
return view;
}
});

mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
mToolbar,
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
) {
public void onDrawerClosed(View view) {
mToolbar.setTitle(mTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}

public void onDrawerOpened(View drawerView) {
mToolbar.setTitle(mDrawerTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);

if (savedInstanceState == null) {
selectItem(0);
}
}

这里是 a video showing Gmail for tablets在这种模式下。

最佳答案

官方的NavigationDrawer 确实在他们的design specification 中提到了“mini-variant”。 ,但没有关于如何使用它的文档。也许它稍后会作为支持库的一部分出现。如果/何时有官方解决方案,将更新答案。

直到,看看ActionsContentView library , 做你想做的事。上次更新是在 2 年前,但它有效,我前一阵子用过。您也可以在 Google Play 上获得它并测试它。

Closed state Opened state

关于android - 如何启用或伪造来自 android.support.v4.widget.DrawerLayout 的 Material Design 指南的迷你变体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31437444/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com