我正在关注建议使用V4 Navigation Drawer的Android教程,它应该在左侧为我提供一个汉堡包导航图标。 相反,如果我使用一个图标,我会得到这个结果:
如果我使用另一个 类似的 图标,那就更糟了,占据了所有空间:
我不明白:
1)如何以左侧方式使用第二个图标,而其他图标继续出现,就像人们对导航抽屉的期望一样?
2)为什么两个不同的图标有这么不同的行为,毕竟我用gimp处理它们给它们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>
答案 0 :(得分:0)
我找到了解决方案, 基本上我下载官方的材料设计图标,它作为一个魅力 https://design.google.com/icons/index.html
尺寸48x48;宽度48像素;高度48像素;位深度32;
我选择了重新排序图标。