您好我正在实施导航抽屉。在那个面板上,我必须显示自定义数字键盘。面板工作正常和数字垫也。但问题是我采取的列表视图的例子。因此,在ActionBarDrawerToogle上,他们实现了onOptionsItemSelected(MenuItem项)。所以我必须删除,因为当我在相对布局中给出任何东西时,我只能看到单行数而不是整数。我可以在这里实现任何其他方法吗?请告诉我。
我修改的代码是:
private DrawerLayout mDrawerLayout;
private RelativeLayout mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (RelativeLayout) findViewById(R.id.left_drawer);
// set a custom shadow that overlays the main content when the drawer opens
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// enable ActionBar app icon to behave as action to toggle nav drawer
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// if (item != null && item.getItemId() == android.R.id.home) {
if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
mDrawerLayout.closeDrawer(Gravity.RIGHT);
} else {
mDrawerLayout.openDrawer(Gravity.RIGHT);
}
// }
return false;
}
};
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// The action bar home/up action should open or close the drawer.
// ActionBarDrawerToggle will take care of this.
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()...
*/
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}
和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">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false" />
<RelativeLayout
android:id="@+id/left_drawer"
android:layout_width="500dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:background="#FFFFFF">
<!-- <LinearLayout
android:id="@+id/linearLayoutH1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:orientation="vertical"
android:weightSum="1" >
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="false"
android:layout_weight=".50"
/>
</LinearLayout>-->
<LinearLayout
android:id="@+id/linearLayoutH2"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
<Button
android:id="@+id/button1"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/one"
android:textSize="40sp" />
<Button
android:id="@+id/button2"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/two"
android:textSize="40sp" />
<Button
android:id="@+id/button3"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/three"
android:textSize="40sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayoutH3"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
<Button
android:id="@+id/button4"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/four"
android:textSize="40sp" />
<Button
android:id="@+id/button5"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/five"
android:textSize="40sp" />
<Button
android:id="@+id/button6"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:background="@drawable/six"
android:textSize="40sp" />
</LinearLayout>
</RelativeLayout>
提前致谢