0

So i'm new to android programming

im going to add two action bar , but when i add the second action bar , it fills the old one , not making a new one .

i already use the holo light theme .

this is my manifest file

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

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

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

    <!-- Splash Screen Activity -->
    <activity
        android:name=".SplashScreen"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <!-- Login Activity -->
    <activity
        android:name=".LoginActivity"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".SecondActivity"
        android:label="@string/about_us"
        android:parentActivityName=".LoginActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.orionpreneur.MainActivity" />
    </activity>
    <activity
        android:name=".About"
        android:label="@string/title_activity_about"
        android:parentActivityName=".LoginActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.orionpreneur.MainActivity" />
    </activity>
    </application>
</manifest>

this is my main_activity_menu.xml code

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
 <!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
      android:icon="@drawable/ic_action_search"
      android:title="@string/action_search"
      android:showAsAction="always" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/about"
      android:title="@string/about"
      android:showAsAction="always"/>    
</menu>

this is my MainActivity.java code

package com.example.orionpreneur;

import android.app.ActionBar;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class LoginActivity extends ActionBarActivity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main_activity_menu, 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.
     switch (item.getItemId()) {
        case R.id.action_search:
            Toast.makeText(this, "you've pressed the search button !",    Toast.LENGTH_SHORT).show();
            return true;
        case R.id.about:
            Intent in = new Intent(this, About.class );
            startActivity(in);
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }
}

i wanted the search button to be added in separated bar like this

https://developer.android.com/images/training/basics/actionbar-actions.png

i'm desperate , sorry if my question is already asked .

thanks :)))

  • 4
    `in separated bar like this` ... I see only **1** ActionBar. – Phantômaxx Jan 02 '15 at 09:45
  • 1
    you don't need separate `Action Bar` to just place a search button. Create new `xml` file in your `res->menu` folder with search item included, and inside `onCreateOptionsMenu`, add that `xml` file. `getMenuInflater().inflate(R.menu.yourXML, menu)` – Sufiyan Ghori Jan 02 '15 at 09:47
  • If you want to split your ActionBar, follow the directions reported [here](http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar) – Phantômaxx Jan 02 '15 at 09:49
  • Do you want a split actionbar? – gsanskar Jan 02 '15 at 09:51
  • sorry , turns out there's only 1 action bar :) . i mean , i want to place a search button but when i added the search item on my xml menu file , it keeps adding to the same button . – blackmenthor Jan 02 '15 at 11:53
  • In my opinion you can add only one action for an Activity. – Adarsh Gowda Jan 02 '15 at 12:11
  • http://developer.android.com/training/search/setup.html refer this page for search action bar. – Adarsh Gowda Jan 02 '15 at 12:14
  • idk , i just doesnt help . i'm using splash screen activity for my app . does it matter ? – blackmenthor Jan 02 '15 at 13:04

1 Answers1

0

*remove this *

 android:uiOptions="splitActionBarWhenNarrow"
 android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen
wadali
  • 2,221
  • 1
  • 20
  • 38
  • its not working . i dont know , i followed all the instructions from developer.android.com but it keeps coming from the same button – blackmenthor Jan 02 '15 at 11:56