gpt4 book ai didi

android - fragment 更换后抽屉切换不动画

转载 作者:行者123 更新时间:2023-11-29 01:24:52 25 4
gpt4 key购买 nike

我有一个带有抽屉导航的 Activity ,它可以正常工作。唯一的问题是汉堡包菜单在第一次 fragment 替换后没有动画。

public class Main extends AppCompatActivity {

// lots of attributes

@Override
protected void onCreate(Bundle in) {
super.onCreate(in);
setContentView(R.layout.activity_main);
actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
setupDrawer();
}

public void onEventMainThread(LoadedLEsEvent event) {
setupDrawer();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (drawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}

void setupDrawer() {
drawerToggle = new ActionBarDrawerToggle(this, navDrawer, R.string.drawer_open, R.string.drawer_closed) {

public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
invalidateOptionsMenu();
}

public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
invalidateOptionsMenu();
}
};
drawerToggle.setDrawerIndicatorEnabled(true);
navDrawer.setDrawerListener(drawerToggle);
menuListAdapter = new MenuListAdapter(this, R.layout.drawer_item, someList);
menuListView.setAdapter(menuListAdapter);
menuListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//Replaces the frame layout with a fragment
}
});
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggles
drawerToggle.onConfigurationChanged(newConfig);
}

所以基本上它工作正常,直到我用 fragment 替换 FrameLayout。从这里开始,抽屉仍然可以使用,但汉堡包菜单根本没有动画。

最佳答案

所以问题是我每次调用 setupDrawer() 时都初始化了 drawerToggle。将 drawerToggle = new ActionBarDrawerToggle(...) {...}; 移动到 onCreate() 就成功了。

关于android - fragment 更换后抽屉切换不动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34609552/

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