【发布时间】:2023-03-30 15:05:02
【问题描述】:
这就是我的代码的样子,我的活动扩展了活动。当我返回箭头菜单图标时,我无法获取汉堡菜单图标。我不想要。
mainactivity中的代码:
ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.action_bar);
actionBar.setDisplayShowCustomEnabled(true);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
menu_list = new ArrayAdapter<String>(this, R.layout.drawer_list,
getResources().getStringArray(R.array.menu_options));
mDrawerList.setAdapter(menu_list);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,R.drawable.ic_drawer ,R.string.app_name, R.string.app_name);
mDrawerLayout.setDrawerListener(mDrawerToggle);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
action_bar.xml 中的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical"
android:background="#29ABE2" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical"
android:textColor="#FFF"
android:textSize="25dp"
android:text="DataVision" />
</LinearLayout>
其他方法:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle
// If it returns true, then it has handled
// the nav drawer indicator touch event
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...
return super.onOptionsItemSelected(item);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
【问题讨论】:
-
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,R.drawable.ic_drawer,R.string.app_name, R.string.app_name);这条线根本不起作用。对于那个 mDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_drawer); n 即使这不起作用,我也不知道我做错了什么或错过了什么
标签: android android-activity android-actionbar navigation-drawer drawerlayout