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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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>
回答2:
//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);
回答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));