[英]Android Navigation Drawer / DrawerLayout…toggle not working correctly
我不明白,我遵循每個教程都遇到了同樣的問題。 另一方面,在某些設備中,我將ic_drawer(三行圖標)作為按鈕來打開菜單。 我在大多數其他設備上都看到了Up插入符號(箭頭)圖標。 我真的不明白是什么問題。
這是代碼:
主要活動:
protected void onCreate(Bundle savedInstanceState) {
DrawerLayout drawer = (DrawerLayout)findViewById(R.id.DrawerLayout);
ListView menu = (ListView)findViewById(R.id.Menu);
String[] listElements = getResources().getStringArray(R.array.listElements);
ActionBarToggle toggle = new ActionBarDrawerToggle(
this, drawer,
R.drawable.ic_drawer,
R.string.open,
R.string.close){
public void onDrawerClosed(View v){
super.onDrawerClosed(v);
getActionBar().setTitle(title);
invalidateOptionsMenu();
}
public void onDrawerOpened(View v){
super.onDrawerOpened(v);
getActionBar().setTitle("Menu de l'application");
invalidateOptionsMenu();
}
};
drawer.setDrawerListener(toggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
toggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
toggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns
// true, then it has handled the app icon touch event
if (toggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...
return super.onOptionsItemSelected(item);
}
抽屜!
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include
android:id="@+id/ContenuPrincipal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/activity_main_relative"
/>
<!-- ListView... La liste des options du menu -->
<ListView
android:id="@+id/Menu"
android:layout_width="250dp"
android:layout_height="fill_parent"
android:choiceMode="singleChoice"
android:layout_gravity="start"
android:background="#333"
android:divider="#666"
android:dividerHeight="1dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
/>
</android.support.v4.widget.DrawerLayout>
表現:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.usthb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="app.usthb.MainActivity"
android:label="@string/app_name" >
</activity>
<activity android:name="Acceuil"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Ecran2"
android:label="@string/Ecran2">
</activity>
</application>
</manifest>
好吧,這是代碼,就像我說的那樣; 在某些設備(例如我的模擬器)上可以完美運行,但是在其他設備(例如S3)上,我只能使用Up Caret而不是3行圖標。 我真的很感謝您的幫助。 謝謝。
將ActionBar設置為不與Home結合使用:
getActionBar().setDisplayHomeAsUpEnabled(false);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.