gpt4 book ai didi

android - 抽屉导航 fragment 中不显示汉堡包图标

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:11:42 24 4
gpt4 key购买 nike

我正在为抽屉导航使用 Fragement,因此不能使用 onPostCreated 调用 syncState

public class NavigationDrawerFragment extends Fragment{
....

activityCreated 上调用 syncState()

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Indicate that this fragment would like to influence the set of actions in the action bar.
setHasOptionsMenu(true);
mDrawerToggle.syncState();
}

为图标使用ic_drawer

public void setUp(int fragmentId, DrawerLayout drawerLayout) {
mFragmentContainerView = getActivity().findViewById(fragmentId);
mDrawerLayout = drawerLayout;

// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// set up the drawer's list view with items and click listener

ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);

// ActionBarDrawerToggle ties together the the proper interactions
// between the navigation drawer and the action bar app icon.
mDrawerToggle = new ActionBarDrawerToggle(
getActivity(), /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
R.string.navigation_drawer_close /* "close drawer" description for accessibility */
) {
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
if (!isAdded()) {
return;
}

getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
}

@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (!isAdded()) {
return;
}

if (!mUserLearnedDrawer) {
// The user manually opened the drawer; store this flag to prevent auto-showing
// the navigation drawer automatically in the future.
mUserLearnedDrawer = true;
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(getActivity());
sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
}

getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
}


};

不知道哪里出了问题。请帮忙!

最佳答案

我也遇到过这个问题。对我来说,导入 android.support.v7.app.ActionBarDrawerToggle 而不是 android.support.v4.app.ActionBarDrawerToggle 修复了它。您还必须在定义 mDrawerToggle 时删除 R.drawable.ic_drawer 参数:

mDrawerToggle = new ActionBarDrawerToggle(
获取 Activity (),
mDrawerLayout,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close
)

如果这不起作用,请尝试 this question 的一些答案.

关于android - 抽屉导航 fragment 中不显示汉堡包图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31484147/

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