导航 Drawable 中 icon_drawable 的问题
Problems with icon_drawable in navegation Drawable
我试图在 ActionBar 中显示 Icon_drawble,但是当 R.drawable.ic_drawer 位于第一个位置时,在操作栏中显示 return 箭头。
像这样:
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
R.drawable.ic_drawer,
R.string.drawer_open,
R.string.drawer_close
) {
我需要展示这样的东西,但是上面的代码不起作用。
如果我将 R.drawable.ic_drawer 更改为另一个位置,它会给我以下 logcat 错误。
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
R.string.drawer_open,
R.drawable.ic_drawer,//another position
R.string.drawer_close
)
Logcat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.navegatiodrawer/com.example.navegatiodrawer.MainActivity}: android.content.res.Resources$NotFoundException: File Open navigation drawer from drawable resource ID
这似乎是 AppCompat 库最新版本中的错误。
部分混淆可能是由于 Android Studio 的新项目向导在您创建新的导航抽屉时生成错误代码 activity- 它使用 v4 support library ActionBarDrawerToggle
, which is deprecated. Instead, it should use the v7 support library ActionBarDrawerToggle
。
您有两个选择:
最好的选择是切换到 v7 ActionBarDrawerToggle
。为此,请将您的导入更改为使用 android.support.v7.app.ActionBarDrawerToggle
而不是 android.support.v4.app.ActionBarDrawerToggle
。您需要做的唯一其他更改是完全删除 ic_drawer
参数 - 较新版本的切换会自动生成您正在寻找的汉堡包。
如果您坚持使用 v4 切换或自定义图标,您可以恢复到旧版本的支持库。在创建新的导航抽屉 activity 时使用默认生成的项目,我能够通过在我的 build.gradle.
中恢复到 com.android.support:appcompat-v7:22.1.0
来回避这个错误
已经有 a bug in the issue tracker 用于更新向导生成的代码。我不希望 v4 切换得到修复,因为它已被弃用。
我试图在 ActionBar 中显示 Icon_drawble,但是当 R.drawable.ic_drawer 位于第一个位置时,在操作栏中显示 return 箭头。
像这样:
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
R.drawable.ic_drawer,
R.string.drawer_open,
R.string.drawer_close
) {
我需要展示这样的东西,但是上面的代码不起作用。
如果我将 R.drawable.ic_drawer 更改为另一个位置,它会给我以下 logcat 错误。
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
R.string.drawer_open,
R.drawable.ic_drawer,//another position
R.string.drawer_close
)
Logcat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.navegatiodrawer/com.example.navegatiodrawer.MainActivity}: android.content.res.Resources$NotFoundException: File Open navigation drawer from drawable resource ID
这似乎是 AppCompat 库最新版本中的错误。
部分混淆可能是由于 Android Studio 的新项目向导在您创建新的导航抽屉时生成错误代码 activity- 它使用 v4 support library ActionBarDrawerToggle
, which is deprecated. Instead, it should use the v7 support library ActionBarDrawerToggle
。
您有两个选择:
最好的选择是切换到 v7
ActionBarDrawerToggle
。为此,请将您的导入更改为使用android.support.v7.app.ActionBarDrawerToggle
而不是android.support.v4.app.ActionBarDrawerToggle
。您需要做的唯一其他更改是完全删除ic_drawer
参数 - 较新版本的切换会自动生成您正在寻找的汉堡包。如果您坚持使用 v4 切换或自定义图标,您可以恢复到旧版本的支持库。在创建新的导航抽屉 activity 时使用默认生成的项目,我能够通过在我的 build.gradle.
中恢复到
com.android.support:appcompat-v7:22.1.0
来回避这个错误
已经有 a bug in the issue tracker 用于更新向导生成的代码。我不希望 v4 切换得到修复,因为它已被弃用。