Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I position my actionbar list navigation on the right side?

enter image description here

This image demonstrats what I need to do. I need the dropdown menu to always stay on the left next to the overflow menu icon

How can i do this?

My styles.xml

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

    <!-- Variation on the Holo Light theme that styles the Action Bar -->
    <style name="Theme.AndroidDevelopers" parent="Theme.Sherlock.Light">
        <item name="android:actionBarItemBackground">@drawable/ad_selectable_background</item>
        <item name="actionBarItemBackground">@drawable/ad_selectable_background</item>
        <item name="android:popupMenuStyle">@style/MyPopupMenu</item>
        <item name="popupMenuStyle">@style/MyPopupMenu</item>
        <item name="android:dropDownListViewStyle">@style/MyDropDownListView</item>
        <item name="dropDownListViewStyle">@style/MyDropDownListView</item>
        <item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item>
        <item name="actionBarTabStyle">@style/MyActionBarTabStyle</item>
        <item name="android:actionDropDownStyle">@style/MyDropDownNav</item>
        <item name="actionDropDownStyle">@style/MyDropDownNav</item>
        <item name="android:listChoiceIndicatorMultiple">@drawable/ad_btn_check_holo_light</item>
        <item name="android:listChoiceIndicatorSingle">@drawable/ad_btn_radio_holo_light</item>

        <!-- <item name="android:actionOverflowButtonStyle">@style/MyOverflowButton</item> -->
    </style>

    <!-- style the overflow menu -->
    <style name="MyPopupMenu" parent="Widget.Sherlock.Light.PopupMenu">
        <item name="android:popupBackground">@drawable/ad_menu_dropdown_panel_holo_light</item>
    </style>

    <!-- style the items within the overflow menu -->
    <style name="MyDropDownListView" parent="Widget.Sherlock.ListView.DropDown">
        <item name="android:listSelector">@drawable/ad_selectable_background</item>
    </style>

    <!-- style for the tabs -->
    <style name="MyActionBarTabStyle" parent="Widget.Sherlock.Light.ActionBar.TabBar">
        <item name="android:background">@drawable/actionbar_tab_bg</item>
    </style>

    <!-- style the list navigation -->
    <style name="MyDropDownNav" parent="Widget.Sherlock.Light.Spinner.DropDown.ActionBar">
        <item name="android:background">@drawable/ad_spinner_background_holo_light</item>
        <item name="android:popupBackground">@drawable/ad_menu_dropdown_panel_holo_light</item>
        <item name="android:dropDownSelector">@drawable/ad_selectable_background</item>

    </style>

    <!--
         the following can be used to style the overflow menu button
         only do this if you have an *extremely* good reason to!!


    -->
    <!--
    <style name="MyOverflowButton" parent="Widget.Sherlock.ActionButton.Overflow">
        <item name="android:src">@drawable/ic_menu_view</item>
        <item name="android:background">@drawable/action_button_background</item>
    </style>


    -->

  <style name="customRatingBar" parent="@android:style/Widget.RatingBar">
    <item name="android:progressDrawable" >@drawable/custom_ratingbar</item>
    <item name="android:indeterminateDrawable">@drawable/money_off</item>
     <item name="android:minHeight">10dip</item>
       <item name="android:maxHeight">15dip</item>
       <item name="android:scaleType">centerInside</item>

</style>
</resources>
like image 212
code511788465541441 Avatar asked Mar 31 '13 11:03

code511788465541441


1 Answers

As an example for implementing it as Action view, "Emanuel Moecklin" is the owner of following Code

ActionBar actionBar = getSupportActionBar();
    final Context context = actionBar.getThemedContext();
    final String[] entries = new String[] { "Entry 1", "Entry 2", "Entry 3" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,
            R.layout.sherlock_spinner_item, entries);
    adapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);

    // create ICS spinner
    IcsSpinner spinner = new IcsSpinner(this, null,
            R.attr.actionDropDownStyle);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(IcsAdapterView<?> parent, View view,
                int position, long id) {
            Toast.makeText(context, "Item selected: " + entries[position],
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onNothingSelected(IcsAdapterView<?> parent) {
        }
    });

    // configure custom view
    IcsLinearLayout listNavLayout = (IcsLinearLayout) getLayoutInflater()
            .inflate(R.layout.abs__action_bar_tab_bar_view, null);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;
    listNavLayout.addView(spinner, params);
    listNavLayout.setGravity(Gravity.RIGHT); // <-- align the spinner to the
                                                // right

    // configure action bar
    actionBar.setCustomView(listNavLayout, new ActionBar.LayoutParams(
            Gravity.RIGHT));
    actionBar.setDisplayShowCustomEnabled(true);
like image 143
Ayman Mahgoub Avatar answered Oct 22 '22 09:10

Ayman Mahgoub