【问题标题】:How to put the icon to the left of action bar tabs如何将图标放在操作栏选项卡的左侧
【发布时间】:2013-03-28 03:07:48
【问题描述】:

我正在使用 ActionBar.Tab,它们总是出现在屏幕的左侧。我想把活动图标放在标签的左边,但它总是出现在标签的右边。我怎样才能将他们的位置移动到我想要的位置?

【问题讨论】:

    标签: android android-actionbar


    【解决方案1】:

    这对我来说就像做梦一样: 在活动中我有这个:

        //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】:

      //使用您的自定义 xml 视图在左侧显示您的图标

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

      【讨论】:

      • 我这样做了,但自定义视图将出现在选项卡和操作栏图标之间。如何将自定义视图放置在选项卡的左侧而不是选项卡和操作栏图标之间?
      【解决方案3】:

      如果您在活动中,请在您的 onCreate() 方法上

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

      【讨论】:

        猜你喜欢
        • 2023-03-27
        • 2010-12-19
        • 2020-05-05
        • 1970-01-01
        • 2020-05-24
        • 1970-01-01
        • 2017-07-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多