How to put the icon to the left of action bar tabs
-
26-10-2019 - |
문제
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 I move their position to where I want?
해결책
here is what works for me like a dream: in the Activity I have this:
//hiding default app icon
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
//displaying custom ActionBar
View mActionBarView = getLayoutInflater().inflate(R.layout.my_action_bar, null);
actionBar.setCustomView(mActionBarView);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM)
my_action_bar.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/turquoise">
<ImageButton
android: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>
다른 팁
//use your custom xml view to show your icon at left
View actionBarView = getLayoutInflater().inflate(R.layout.action_bar_custom_view, null);
actionBar.setCustomView(actionBarView);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
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));
제휴하지 않습니다 StackOverflow