9

I have need to make two action bars , I am using actionBarSherlock by the way . So what I need exactly is to put a "Welcome screen" toggle on the normal action bar up , and add two normal ActionBar Action options . Similar to what I need are Gmail and Maps like here : http://cdn.androidcommunity.com/wp-content/uploads/2012/03/Screenshot_2012-03-28-12-58-16.png (They didn't allow me to post an image for reputation is low , see the link please)

This Maps app has an upper and bottom action bar , exactly what I need , because once I reach the point where I can add the second actionbar I know where to start ...

I have searched for about a week about this topic and I have found a few similar questions , but however I have understood non of the answers ; the answers were about a custom view which I am not (at all) familiar with and I can't understand a thing , but yes I tried to make a "custom view" from whatever I thought is right and I got crrassshheesss which I didn't find any solution for ... If you may plz show me as an example this Maps app how is it using those two action bars ?? (I don't want to navigate like in maps and gmail , but only the two actionbars)

Here is some of my code :

//Part of my MainActivity.class
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
        MenuInflater inf = getSupportMenuInflater();
        inf.inflate(R.menu.upper_navbar, menu);

        final String name = "welcome";
        final SharedPreferences pref = getSharedPreferences(name, 0);
        final Editor edit = pref.edit();
        boolean oldState = pref.getBoolean("w", true);
        ToggleButton tog = (ToggleButton) menu.findItem(R.id.welcome_screen).getActionView();
        if(oldState){
            tog.setChecked(true);

        }else{
            tog.setChecked(false);
        }

        tog.setOnCheckedChangeListener(new OnCheckedChangeListener() {



            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    edit.putBoolean("w", true);
                    edit.apply();
                }else{
                    edit.putBoolean("w", false);
                    edit.apply();
                }


            }
        });
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

    return super.onOptionsItemSelected(item);
    }

My Manifest :

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

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="16" />

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="seaskyways.editpad.Splash"
            android:theme="@style/Theme.Sherlock.Dialog.NoActionBar"


            android:label="Splash" >
            <intent-filter>
                <action android:name="android.intent.action.SPLASH" />

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

</manifest>

And my menus which I intend to put them in my action bars ...

menu\activity_main.xml

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


    <item android:id="@+id/bottom_copy"  android:title="Copy" android:orderInCategory="3" android:showAsAction="ifRoom|withText" />
    <item android:id="@+id/bottom_paste" android:title="Paste" android:orderInCategory="2" android:showAsAction="ifRoom|withText" />

</menu>

menu\upper_navbar.xml (Should have named it upper_actionbar but its just a thinking mistake , its a name afterall , :/ plz proceed )

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

     <item
        android:id="@+id/welcome_screen"
        android:orderInCategory="1"
        android:showAsAction="ifRoom|withText"
        android:title="Welcome Screen"
        android:actionLayout="@layout/toggle"

        />

</menu>

If you need anymore info please tell me , I will tell , its for me and everyone else afterall !

EDIT !!! : I found a much near example to my question , the wifi settings (http://omgdroid.com/wp-content/uploads/2012/07/Screenshot_2012-07-06-01-34-29-576x1024.png) It uses a switch in the normal actionbar and a normal split actionbar down ! Exactly what I need !

EDIT 2 !!!! : Here is a screenshot from my Galaxy nexus using a custom ROM based over aosp , This is exactly what I need and mean :

Settings-Wifi: https://lh4.googleusercontent.com/-aeL_sHjIcQQ/UPVptGQiuqI/AAAAAAAAAGE/UGc-CuLP4Qw/s512/Screenshot_2013-01-15-16-36-32.png

Settings-Bluetooth: lh3*googleusercontent.com/-4j6ca1Nm1VI/UPVqAiDn_PI/AAAAAAAAAGM/LLB2ILWVjQY/s512/Screenshot_2013-01-15-16-38-14.png

EDIT 3 !!! : Big progress in my investigation in the Bluetooth and Wifi , and as I said and asked , they were true actionbars ! see what I got in Settings-Bluetooth:

BluetoothSettings.class/onCreateOptionsMenu :

@Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        if (mLocalAdapter == null) return;
        boolean bluetoothIsEnabled = mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON;
        boolean isDiscovering = mLocalAdapter.isDiscovering();
        int textId = isDiscovering ? R.string.bluetooth_searching_for_devices :
            R.string.bluetooth_search_for_devices;
        menu.add(Menu.NONE, MENU_ID_SCAN, 0, textId)
                .setEnabled(bluetoothIsEnabled && !isDiscovering)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        menu.add(Menu.NONE, MENU_ID_RENAME_DEVICE, 0, R.string.bluetooth_rename_device)
                .setEnabled(bluetoothIsEnabled)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        menu.add(Menu.NONE, MENU_ID_VISIBILITY_TIMEOUT, 0, R.string.bluetooth_visibility_timeout)
                .setEnabled(bluetoothIsEnabled)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        menu.add(Menu.NONE, MENU_ID_SHOW_RECEIVED, 0, R.string.bluetooth_show_received_files)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        super.onCreateOptionsMenu(menu, inflater);
    }

These can be options are clearly shown in the splitActionBarDown with the exact properties up ...

now :

BluetoothSettings.class/addPreferencesForActivity :

@Override
    void addPreferencesForActivity() {
        addPreferencesFromResource(R.xml.bluetooth_settings);

        Activity activity = getActivity();

        Switch actionBarSwitch = new Switch(activity);

        if (activity instanceof PreferenceActivity) {
            PreferenceActivity preferenceActivity = (PreferenceActivity) activity;
            if (preferenceActivity.onIsHidingHeaders() || !preferenceActivity.onIsMultiPane()) {
                final int padding = activity.getResources().getDimensionPixelSize(
                        R.dimen.action_bar_switch_padding);
                actionBarSwitch.setPadding(0, 0, padding, 0);
                activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
                        ActionBar.DISPLAY_SHOW_CUSTOM);
                activity.getActionBar().setCustomView(actionBarSwitch, new ActionBar.LayoutParams(
                        ActionBar.LayoutParams.WRAP_CONTENT,
                        ActionBar.LayoutParams.WRAP_CONTENT,
                        Gravity.CENTER_VERTICAL | Gravity.END));
            }
        }

        mBluetoothEnabler = new BluetoothEnabler(activity, actionBarSwitch);

        setHasOptionsMenu(true);
    }

Noting that this class isn't extending Activity , it extends DeviceListPreferenceFragment ...

Now that we know it's possible to have two actionbars(split and normal) in the same time , we need a way to simplify that , maybe by a class or library ??

Seaskyways
  • 3,630
  • 3
  • 26
  • 43

3 Answers3

5

That is a split action bar. It is available for handset devices with a screen width of 400dp< To enable split action bar, simply add uiOptions="splitActionBarWhenNarrow" to your or manifest element.

Edit: The second image is indeed not a split action bar. These are just buttons with the buttonBarButtonStyle attribute. Look into this here.

Edit:

splitActionBarWhenNarrow has been deprecated.

Community
  • 1
  • 1
Ahmad
  • 69,608
  • 17
  • 111
  • 137
3

I have need to make two action bars

Then you are on your own. This is not supported in Android or ActionBarSherlock, other than the split action bar, which you dismissed.

Similar to what I need are Gmail and Maps like here

That is a split action bar, specifically one using overlays. This sample project demonstrates this technique.

This Maps app has an upper and bottom action bar , exactly what I need

Then use the split action bar, via android:uiOptions="splitActionBarWhenNarrow" in your <activity> element, the way that Maps does. The main Maps activity uses android:uiOptions="splitActionBarWhenNarrow".

If you may plz show me as an example this Maps app how is it using those two action bars ?

As noted above, this sample project demonstrates this technique.

I know how to make one action bar (split and normal)

Maps is using a split action bar.

but what I need is making them both at a time so I can have two actionbars !

In your screenshot, you will notice that Maps has a split action bar, and they are both on the screen at the same time. This is the way split action bars work, in narrow situations. The same Maps app does not show the split action bar when the screen is not presently narrow.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I got a better , an exact example of what I want , see the Wifi in the stock android Settings app , it has a switch next to the title (normal action bar) and a normal split action bar down ! http://omgdroid.com/wp-content/uploads/2012/07/Screenshot_2012-07-06-01-34-29-576x1024.png – Seaskyways Jan 14 '13 at 21:47
  • @Seaskyways: That is not two action bars. Those are two buttons at the bottom of the layout, or something along those lines. Action bar action item names are in all caps, for example. – CommonsWare Jan 14 '13 at 21:56
  • 1
    @Seaskyways: And your screenshot is not of the AOSP version. The AOSP version of this screen does not have the buttons at the bottom, but instead uses a split action bar, where "Scan" and "Advanced" appear in the action overflow. – CommonsWare Jan 14 '13 at 22:25
  • @Seaskyways: I was referring to the screenshot in your first comment on my answer. That is not the AOSP version. By style, my guess is that it is from some Samsung phone, but that is just a guess. – CommonsWare Jan 15 '13 at 15:06
  • yes right it is samsung's , but am asking you to check the aosp version , but that is what I found over google , see my own screenshot from my galaxy nexus 4.2.1 ... – Seaskyways Jan 15 '13 at 16:57
  • @Seaskyways: Quoting myself from an earlier comment: "The AOSP version of this screen does not have the buttons at the bottom, but instead uses a split action bar, where "Scan" and "Advanced" appear in the action overflow." – CommonsWare Jan 15 '13 at 16:58
  • how can it use a split action bar down and a switch next to the title ?!?!?!?!?! – Seaskyways Jan 15 '13 at 17:48
  • @Seaskyways: That is probably a custom navigation view, if I had to guess. Since the AOSP code is open, you are welcome to do the rest of the investigation yourself. – CommonsWare Jan 15 '13 at 17:49
  • I thought of investigation too , but google gives us the sdk , where can I find the source ?? – Seaskyways Jan 15 '13 at 17:54
  • @Seaskyways: http://source.android.com. There is also a GitHub mirror at http://github.com/android. – CommonsWare Jan 15 '13 at 18:00
  • thanks alot for contributing for my help , I think I will investigate it out and write the very righteous answer ! – Seaskyways Jan 15 '13 at 20:25
-1

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

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

//this is main line for that

    android:uiOptions="splitActionBarWhenNarrow"  




     >
    <activity
        android:name="com.example.androidactionbarbottam.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>

This is main line for bottam side

android:uiOptions="splitActionBarWhenNarrow"

Amitsharma
  • 1,577
  • 1
  • 17
  • 29
  • 1
    u can add images or Text at bottom ........this will work without create any problem i have same problem i have dun from this line code – Amitsharma Jan 15 '14 at 16:01