سؤال

AFAIK ActionBar should be by default be displayed at top, but in my case it's coming at bottom.

I've followed the standard tutorial and kept all basics in check.

Here's my code and supporting screenshot:

MainActivity.java

package com.android.actionbardemo;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ActionBar actionBar = getActionBar();
        actionBar.show();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.main, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {

        case R.id.home:
            Toast.makeText(this, "Home Option Selected", Toast.LENGTH_SHORT)
                    .show();
            return true;

        case R.id.java:
            Toast.makeText(this, "Java Option Selected", Toast.LENGTH_SHORT)
                    .show();
            return true;

        case R.id.android:
            Toast.makeText(this, "Android Option Selected", Toast.LENGTH_SHORT)
                    .show();
            return true;

        default:
            return super.onOptionsItemSelected(item);
        }

    }
}

main.xml (menu)

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_settings"
        android:showAsAction="never"
        android:title="@string/action_settings"/>
    <item
        android:id="@+id/home"
        android:icon="@drawable/home"
        android:showAsAction="ifRoom"
        android:title="Home"/>

    <item
        android:id="@+id/java"
        android:icon="@drawable/java"
        android:showAsAction="ifRoom"
        android:title="Java"/>

    <item
        android:id="@+id/android"
        android:icon="@drawable/android"
        android:showAsAction="ifRoom"
        android:title="Android"/>

</menu>

Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.actionbardemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:uiOptions="splitActionBarWhenNarrow" >
        <activity
            android:name="com.android.actionbardemo.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

screenshot

Am I doing anything wrong?

Any help appreciated.

هل كانت مفيدة؟

المحلول

You're using the uiOptions splitActionBarWhenNarrow in your application tag.

From the docs:

Add a bar at the bottom of the screen to display action items in the ActionBar, when constrained for horizontal space (such as when in portrait mode on a handset). Instead of a small number of action items appearing in the action bar at the top of the screen, the action bar is split into the top navigation section and the bottom bar for action items. This ensures a reasonable amount of space is made available not only for the action items, but also for navigation and title elements at the top. Menu items are not split across the two bars; they always appear together.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top