cleve23 0 Newbie Poster

Hi all,

I followed a tutorial on using the action bar and i face problem trying to split it. All my items just get fitted in to the overflow menu. Please help me with it.
Below is my code:

AndroidManifest.xml

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" 
        >

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" 
            android:uiOptions="splitActionBarWhenNarrow" >
            <meta-data 
                android:name="android.support.UI_OPTIONS"
                android:value="splitActionBarWhenNarrow"
                />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

MainActivity.java

package com.example.androidapptutorial;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        MenuInflater inflater = getMenuInflater();
        //getMenuInflater().inflate(R.menu.main, menu);
        inflater.inflate(R.menu.main,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        //int id = item.getItemId();
        /*
        if (id == R.id.action_settings) {
            return true;
        }
        */
        switch(item.getItemId())
        {
        case R.id.computer:
            return true;
        case R.id.video:
            return true;
        case R.id.photo:
            return true;
        case R.id.call:
            return true;
        case R.id.send:
            return true;
        default:
                return super.onOptionsItemSelected(item);
        }
    }
}

main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.androidapptutorial.MainActivity" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="ifRoom"
        />

    <item
        android:id="@+id/computer"
        android:icon="@drawable/ic_action_computer"
        android:title="@string/computer"
        app:showAsAction="ifRoom"
        />

    <item
        android:id="@+id/video"
        android:icon="@drawable/ic_action_video"
        android:title="@string/video"
        app:showAsAction="ifRoom"
        />

    <item
        android:id="@+id/call"
        android:icon="@drawable/ic_action_call"
        android:title="@string/call"
        app:showAsAction="ifRoom"
        />


    <item
        android:id="@+id/photo"
        android:icon="@drawable/ic_action_photo"
        android:title="@string/photo"
        app:showAsAction="ifRoom"
        />

    <item
        android:id="@+id/edit"
        android:icon="@drawable/ic_action_edit"
        android:title="@string/photo"
        app:showAsAction="ifRoom"
        />

    <item
        android:id="@+id/send"
        android:icon="@drawable/ic_action_send"
        android:title="@string/photo"
        app:showAsAction="ifRoom"
        />

</menu>

Thanks Alot!!!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.