1

我不明白,我已经按照每个教程进行了同样的问题。另一方面,在某些设备中,我将 ic_drawer(3 行图标)作为打开菜单的按钮;大多数其他设备我都得到了向上插入符号(箭头)图标。我真的不明白有什么问题。

这是代码:

主要活动:

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 行图标。我真的很感激你的帮助。谢谢你。

4

1 回答 1

0

将 ActionBar 设置为不作为 Home :

  getActionBar().setDisplayHomeAsUpEnabled(false);
于 2014-03-27T15:29:19.930 回答