增加操作栏大小时,未显示Sherlock操作栏选项卡

时间:2013-07-22 06:02:34

标签: android tabs actionbarsherlock android-actionbar

我想自定义sherlock操作栏及其标签。

由于我必须显示大约100-150dp大小的应用程序图标图像,并且应用程序图标底部我必须显示标签。

就像这样enter image description here

所以我在样式

中尝试了这段代码
<style name="Theme.Style.Login" parent="@style/Theme.Sherlock.Light">
<!-- For API level <11--->
    <item name="actionBarStyle">@style/Theme.white_style</item>
    <item name="actionBarTabStyle">@style/customLoginActionBarTabStyle</item>
    <item name="actionBarTabBarStyle">@style/customLoginActionBarTabDividerStyle</item> 
<!-- For API level <11--->

<!-- For API level >=11--->
     <item name="android:actionBarTabBarStyle">@style/customLoginActionBarTabStyle</item>
     <item name="android:actionBarStyle">@style/Theme.white_style</item> 
    <item name="android:actionBarTabBarStyle">@style/customLoginActionBarTabDividerStyle</item>
 <!-- For API level >=11--->
</style>

<!-- Signup Login Tab Style theme -->
<style name="customLoginActionBarTabStyle" parent="@style/Widget.Sherlock.Light.ActionBar.TabView">
    <item name="android:background">@drawable/actionbar_tabs_selector_loginsignup</item>

</style> 
<style name="customLoginActionBarTabDividerStyle" parent="@style/Widget.Sherlock.ActionBar.TabBar">
    <item name="divider">@null</item>
    <item name="android:divider">@null</item>
</style> 



<style name="Theme.white_style" parent="@style/Theme.Sherlock.Light">
    <item name="actionBarSize">@dimen/loginactionbar</item>
    <item name="android:actionBarSize">@dimen/loginactionbar</item>
</style> 

等等。

这是我的活动代码

public class SignupLoginActivity extends SherlockActivity implements ActionBar.TabListener {

public static int THEME = R.style.Theme_Style_Login;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(THEME); 
    setContentView(R.layout.main);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setCustomView(R.layout.login_actionbar_customeview);
     actionBar.setDisplayShowTitleEnabled(false);
     actionBar.setDisplayShowCustomEnabled(true);

     actionBar.setLogo(null); 

     View homeIcon = findViewById(
             Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? 
             android.R.id.home : R.id.abs__home);
     ((View) homeIcon.getParent()).setVisibility(View.GONE);
     ((View) homeIcon).setVisibility(View.GONE);

     /*
         * For adding tab
         */
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        for (int i = 1; i <= 2; i++) {     
            ActionBar.Tab tab = actionBar.newTab();
            tab.setText("Tab " + i);
            tab.setTabListener(this);
            actionBar.addTab(tab);
        }
}

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    // TODO Auto-generated method stub

}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    // TODO Auto-generated method stub

}

@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
    // TODO Auto-generated method stub

}


}

所以在这种情况下我可以增加Actionbar高度,但ActionBar Tab没有显示,所以如何实现我想要的结果。

1 个答案:

答案 0 :(得分:0)

最后,我通过这种方式实现了所需的解决方案

<!-- For API Level <11 -->
 <style name="Theme.Style.Login" parent="@style/Theme.Sherlock.Light">
    <item name="actionBarTabStyle">@style/customLoginActionBarTabStyle</item>
    <item name="actionBarDivider">@null</item>   // This will remove divider between tabs
    <item name="actionBarTabTextStyle">@style/customeLoginTabTextStyle</item> // This will increase tab text size
    <item name="actionBarSize">@dimen/loginactionbar</item> // This will increase actionbar size
 </style>
<!-- For API Level <11 -->

<!-- For API Level >=11 -->
 <style name="Theme.Style.Login" parent="@style/Theme.Sherlock.Light">
    <item name="android:actionBarTabStyle">@style/customLoginActionBarTabStyle</item>
    <item name="actionBarDivider">@null</item>   // This will remove divider between tabs
    <item name="android:actionBarTabTextStyle">@style/customeLoginTabTextStyle</item> // This will increase tab text size
    <item name="android:actionBarSize">@dimen/loginactionbar</item> // This will increase actionbar size
 </style>
 <!-- For API Level >=11 -->


<!-- For API Level >=14 -->
 <style name="Theme.Style.Login" parent="@style/Theme.Sherlock.Light">
    <item name="android:actionBarTabStyle">@style/customLoginActionBarTabStyle</item>
    <item name="android:actionBarDivider">@null</item>   // This will remove divider between tabs
    <item name="android:actionBarTabTextStyle">@style/customeLoginTabTextStyle</item> // This will increase tab text size
    <item name="android:actionBarSize">@dimen/loginactionbar</item> // This will increase actionbar size
 </style>
 <!-- For API Level >=14 -->

<!-- Signup Login Tab Style theme -->
<style name="customLoginActionBarTabStyle" parent="@style/Widget.Sherlock.Light.ActionBar.TabView">
    <item name="android:background">@drawable/actionbar_tabs_selector_loginsignup</item>
    <item name="android:paddingTop">20dp</item>
</style> 

<style name="customeLoginTabTextStyle" parent="Widget.Sherlock.ActionBar.TabText">
    <item name="android:textColor">@color/countryname</item>
    <item name="android:textSize">@dimen/logintabtxtsize</item>
</style>