0
我正在关注Android教程,该教程建议使用V4 Navigation Drawer,它应该在左侧给我一个汉堡包导航图标。 反而会发生什么,如果我用一个图标我有这样的结果:导航抽屉图标(用GIMP制作)需要太多空间
我不明白:
1)如何使用第二个图标一种方式在左侧,而其他图标继续出现,就像人们对导航抽屉的期望一样?
2)为什么是两个不同的图标有这样的不同的行为,毕竟我曾将它们与瘸子给他们200x200像素尺寸
我的主类:
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
public class MainActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
getActionBar().setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] provaListaDrawer = {"List1", "List2", "List3"};
mTitle = mDrawerTitle = getTitle();
DrawerLayout mDrawerLayout =
(DrawerLayout) findViewById(R.id.drawer_layout);
actionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.app_drawer, R.string.drawer_open, R.string.drawer_close)
{
/**
* Called when a drawer has settled in a completely closed state.
*/
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getActionBar().setTitle(mTitle);
Log.d("IVO", "onDrawerClosed");
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
/**
* Called when a drawer has settled in a completely open state.
*/
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getActionBar().setTitle(mDrawerTitle);
Log.d("IVO", "onDrawerOpened");
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
}
;
ListView mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_view,provaListaDrawer));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
mDrawerLayout.setDrawerListener(actionBarDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
//
// getActionBar().setHomeButtonEnabled(true);
// ActionBar actionBar = getActionBar();
// actionBar.setDisplayShowHomeEnabled(false);
// actionBar.setDisplayShowCustomEnabled(true);
// actionBar.setDisplayShowTitleEnabled(false);
// View customView = getLayoutInflater().inflate(R.layout.activity_main, null);
// actionBar.setCustomView(customView);
// Toolbar parent =(Toolbar) customView.getParent();
// parent.setContentInsetsAbsolute(0,0);
}
//other methods
}
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"
android:layout_gravity="center"
>
<!-- The main content view -->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_as_list"
android:name="ivano.android.com.xx"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="19dp"
android:background="@drawable/image_background"
android:paddingTop="?android:attr/actionBarSize"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
/>
</android.support.v4.widget.DrawerLayout>
您应该使用[支持导航栏](https://developer.android.com/training/implementing-navigation/nav-drawer.html)。这将有助于协调。 [This](http://codetheory.in/android-navigation-drawer/)博客文章告诉你如何使用默认的汉堡包图标。您可以用任何颜色为主题添加颜色。 – nukeforum
@nukeforum感谢您的关注;对于支持导航栏,您给我的链接与我在帖子中指出的相同,即我想你的意思是使用V4库,这正是我正在使用的。我不明白的是为什么图标的行为与预期不同 – trocchietto