Я использую библиотеки поддержки Android для создания TabBar. Я могу создать TabBar успешно с моими собственными модификациями с использованием стилей, но я не знаю, почему осталось остальное дополнение в первой вкладке и правом дополнении во второй вкладке. Я не могу чтобы удалить их с помощью переопределения стилей.Как удалить вкладку вкладок панели действий?
код файла макета:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false" >
</LinearLayout>
Java код файла:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_contacts);
final ActionBar actionBar = getActionBar();
// Specify that tabs should be displayed in the action bar.
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Create a tab listener that is called when the user changes tabs.
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
@Override
public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
@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
}
};
// Add 3 tabs, specifying the tab's text and TabListener
for (int i = 0; i < 2; i++) {
actionBar.addTab(actionBar.newTab().setText("Tab " + (i + 1))
.setTabListener(tabListener));
}}
Мой код стиля:
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionBarTabStyle">@style/MyActionBar.Tab</item>
<item name="android:actionBarTabTextStyle">@style/My.TabText.Style</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">@color/white</item>
<item name="android:padding">0dp</item>
</style>
<style name="MyActionBar.Tab" parent="@android:style/Widget.Holo.Light.ActionBar.TabBar">
<item name="android:background">@drawable/tab_bar_background</item>
<item name="android:padding">0dp</item>
<item name="android:gravity">center</item>
</style>
<style name="My.TabText.Style" parent="@android:style/Widget.Holo.Light.ActionBar.TabText">
<item name="android:textAppearance">@android:style/TextAppearance.Medium</item>
<item name="android:textSize">15sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/black</item>
<item name="android:textAllCaps">true</item>
<!-- <item name="android:ellipsize">none</item> -->
<item name="android:maxLines">1</item>
</style>
Я привел скриншот ниже для справки.
отправьте свой макет xml. – nurealam11
@ nurealam11 Я добавил код файла xml и код Java. – user818455
, пожалуйста, попробуйте это. Надеюсь, это поможет вам. http://www.survivingwithandroid.com/2013/06/android-action-bar-with-tab.html – nurealam11