Skip to content Skip to sidebar Skip to footer

How To Put The Icon To The Left Of Action Bar Tabs

I am using the ActionBar.Tab, and they always appear at the left of screen. I want to put the activity icon to the left of tabs, but it always appear at the right of tabs. How can

Solution 1:

here is what works for me like a dream: in the Activity I have this:

//hiding default app iconActionBaractionBar= getActionBar();
    actionBar.setDisplayShowHomeEnabled(false);
    //displaying custom ActionBarViewmActionBarView= getLayoutInflater().inflate(R.layout.my_action_bar, null);
    actionBar.setCustomView(mActionBarView);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM)

my_action_bar.xml:

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/turquoise"><ImageButtonandroid:id="@+id/btn_slide"android:layout_height="wrap_content"android:layout_width="wrap_content"android:background="@null"android:scaleType="centerInside"android:src="@drawable/btn_slide"android:paddingRight="50dp"android:onClick="toggleMenu"android:paddingTop="4dp"/></RelativeLayout>

Solution 2:

//use your custom xml view to show your icon at left

ViewactionBarView= getLayoutInflater().inflate(R.layout.action_bar_custom_view, null);
        actionBar.setCustomView(actionBarView);
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

Solution 3:

on your onCreate() method if you are on the activity

actionBar.addTab(actionBar.newTab()
.setIcon(<the icon you want>)
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(this));

Post a Comment for "How To Put The Icon To The Left Of Action Bar Tabs"