ActionBarDrawerToggle没有设置抽屉指示器 [英] ActionBarDrawerToggle is not setting Drawer Indicator
问题描述
我想添加导航抽屉里我的应用程序。一切工作正常,但现在我仍然有箭头图标,虽然我与机器人的ic_drawer取代了它?这是我的code:
私人ActionBarDrawerToggle mDrawerToggle;
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
DrawerLayout mDrawerLayout =(DrawerLayout)findViewById(R.id.drawer_layout);
ExpandableListView mDrawerList =(ExpandableListView)findViewById(R.id.left_drawer);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
GravityCompat.START);
mDrawerList.setAdapter(新DrawerListAdapter(本));
mDrawerList.setOnChildClickListener(新DrawerItemClickListener());
mDrawerToggle =新ActionBarDrawerToggle(这一点,mDrawerLayout,
R.drawable.ic_launcher,R.string.drawer_open,
R.string.drawer_close);
Log.d(Mudit
mDrawerToggle+ mDrawerToggle.isDrawerIndicatorEnabled()); //返回true
mDrawerLayout.setDrawerListener(mDrawerToggle);
getActionBar()setDisplayHomeAsUpEnabled(真)。
getActionBar()setHomeButtonEnabled(真)。
getActionBar()setDisplayShowHomeEnabled(假)。
}
/ **
*当使用ActionBarDrawerToggle,你必须在调用它
* onPostCreate()和onConfigurationChanged()...
* /
@覆盖
保护无效onPostCreate(包savedInstanceState){
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@覆盖
公共无效onConfigurationChanged(配置NEWCONFIG){
super.onConfigurationChanged(NEWCONFIG);
mDrawerToggle.onConfigurationChanged(NEWCONFIG);
}
@覆盖
公共布尔onOptionsItemSelected(菜单项项){
如果(mDrawerToggle.onOptionsItemSelected(项目)){
返回true;
}
返回super.onOptionsItemSelected(项目);
}
XML:
< android.support.v4.widget.DrawerLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / drawer_layout
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
<滚动型
机器人:ID =@ + ID / content_frame
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直>
< / LinearLayout中>
< /滚动型>
< ExpandableListView
机器人:ID =@ + ID / left_drawer
机器人:layout_width =240dp
机器人:layout_height =match_parent
机器人:layout_gravity =开始
机器人:后台=#FFFFFF
机器人:dividerHeight =0dp/>
< /android.support.v4.widget.DrawerLayout>
我已经在寻找各种code样品在线,但所有的人都在做同样的事情。我不知道为什么它不是为我工作。
请帮忙。
您将不得不使用
getActionBar()setDisplayShowHomeEnabled(真)。
而不是
getActionBar()setDisplayShowHomeEnabled(假)。
干杯,
菲利克斯
编辑:这是如何隐藏通过XML图标:
添加到您的styles.xml:(更换机器人:Widget.Holo.Light.ActionBar.Solid与Android:如果你使用的是深色操作栏Widget.Holo.ActionBar.Solid)
<样式名称=ActionBarStyle父=机器人:Widget.Holo.Light.ActionBar.Solid>
<项目名称=机器人:图标> @android:彩色/透明< /项目>
< /风格>
然后将它添加到您在AndroidManifest.xml中定义的主题(标准是AppBaseTheme在/res/values-v11/styles.xml - AppBaseTheme:
<项目名称=机器人:actionBarStyle> @风格/ ActionBarStyle< /项目>
希望这有助于!
I am trying to add the navigation drawer in my app.. Everything is working fine But now I still got the arrow icon although I replaced it with the ic_drawer from Android? Here's my code:
private ActionBarDrawerToggle mDrawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
ExpandableListView mDrawerList = (ExpandableListView) findViewById(R.id.left_drawer);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
GravityCompat.START);
mDrawerList.setAdapter(new DrawerListAdapter(this));
mDrawerList.setOnChildClickListener(new DrawerItemClickListener());
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_launcher, R.string.drawer_open,
R.string.drawer_close);
Log.d("Mudit",
"mDrawerToggle" + mDrawerToggle.isDrawerIndicatorEnabled()); // returns true
mDrawerLayout.setDrawerListener(mDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayShowHomeEnabled(false);
}
/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()...
*/
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
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" >
<ScrollView
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<ExpandableListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ffffff"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
I have looking at various code samples online but all of them are doing same thing. I dont know why it is not working for me.
Please help.
You'll have to use
getActionBar().setDisplayShowHomeEnabled(true);
instead of
getActionBar().setDisplayShowHomeEnabled(false);
Cheers,
Felix
EDIT: Here's how to hide the Icon via XML:
add this to your styles.xml: (Replace android:Widget.Holo.Light.ActionBar.Solid with android:Widget.Holo.ActionBar.Solid if you are using the dark action bar)
<style name="ActionBarStyle" parent="android:Widget.Holo.Light.ActionBar.Solid">
<item name="android:icon">@android:color/transparent</item>
</style>
and then add this to your Theme you have defined in AndroidManifest.xml (Standard is the AppBaseTheme in /res/values-v11/styles.xml - AppBaseTheme:
<item name="android:actionBarStyle">@style/ActionBarStyle</item>
Hope this helps!
这篇关于ActionBarDrawerToggle没有设置抽屉指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!