Android的动作条设置宽度的标签 [英] Android Actionbar set width to the tabs

查看:125
本文介绍了Android的动作条设置宽度的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正忙着对我公司WHMCS应用程序。导航我要使用Tab功能在动作条。

Currently I'm busy on a WHMCS app for my company. As navigation I want to use the Tab functionality in the actionbar.

但是,你怎么能编辑选项卡的宽度是多少?我需要5一起在一个屏幕上,而不需要进行滚动。我已经尝试过一些风格是这样的:

However, how can you edit the width of a tab? I need 5 together on one screen without the need to scroll. I already tried it with some styles like this:

<style name="AppBaseTheme" parent="android:Theme.Light">
</style>

<style name="AppTheme" parent="AppBaseTheme">
    <item name="@android:attr/actionBarTabStyle">@style/tab_nav</item>
    <item name="android:actionBarTabTextStyle">@style/actionBarTabTextStyle</item>
</style>

<style name="actionBarTabTextStyle" parent="android:Widget.Holo.Light.ActionBar.TabText.Inverse">
    <item name="android:padding">1dp</item>
</style>

<style name="tab_nav" parent="android:style/Widget.Holo.Light.Tab">
 <item name="android:paddingLeft">-25dp</item>
</style> 

<style name="CustomTabTextStyle" parent="@android:style/TextAppearance.Holo">
    <item name="android:textColor">#2456c2</item>
</style>

不过,宽度将采用更高的负值时没有虾。

However, the width won't shrimp when using a higher negative value.

推荐答案

我想这可能会帮助你......这code实际上是使绑定到屏幕宽度的动作条,因此标签将自行调整=)

Hi i think this may help you... This code is actually making the actionbar bound to the screen width, so the tabs will adjust by themselves =)

private void setTabsMaxWidth() {
   DisplayMetrics displaymetrics = new DisplayMetrics();
   getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
   int screenWidth = displaymetrics.widthPixels;
   final ActionBar actionBar = getActionBar();
   final View tabView = actionBar.getTabAt(0).getCustomView();
   final View tabContainerView = (View) tabView.getParent();
   final int tabPadding = tabContainerView.getPaddingLeft() + tabContainerView.getPaddingRight();
   final int tabs = actionBar.getTabCount();
   for(int i=0 ; i < tabs ; i++) {
      View tab = actionBar.getTabAt(i).getCustomView();
      TextView text1 = (TextView) tab.findViewById(R.id.text1);
      text1.setMaxWidth(screenWidth/tabs-tabPadding-1);
  }
}

这篇关于Android的动作条设置宽度的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆