[英]How to put the icon to the left of action bar tabs
我正在使用ActionBar.Tab,它们始终显示在屏幕左侧。 我想将活动图标放在选项卡的左侧,但始终显示在选项卡的右侧。 如何将他们的位置移到我想要的位置?
这对我来说就像梦一样起作用:在“活动”中我有以下几点:
//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>
//使用您的自定义xml视图在左侧显示您的图标
View actionBarView = getLayoutInflater().inflate(R.layout.action_bar_custom_view, null);
actionBar.setCustomView(actionBarView);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
在onCreate()
方法上onCreate()
如果您处于活动状态)
actionBar.addTab(actionBar.newTab()
.setIcon(<the icon you want>)
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(this));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.