5

Tôi muốn loại bỏ phần đệm (khoảng trống) giữa các tab của ActionBar.Tùy chỉnh Padding của ActionBar Tabs Hỗ trợ

Tôi đang sử dụng Thư viện hỗ trợ Android V7 (Appcompat) để sử dụng Phân đoạn và ActionBar trong Android 2.2 API 8 dưới dạng minSDK và 4.4 API 19 làm maxSDK.

Tôi đã thử những điều sau đây nhưng nó không thay đổi bất cứ điều gì.

My styles.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android"> 
    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light"> 
    </style> 

    <style name="AppTheme" parent="AppBaseTheme"> 
     <item name="@style/Widget.AppCompat.ActionBar.TabView">@style/TabBarStyle</item> 
    </style> 

    <style name="TabBarStyle" parent="@style/Widget.AppCompat.ActionBar.TabView"> 
     <item name="android:paddingLeft">2dp</item> 
     <item name="android:paddingRight">2dp</item> 
    </style> 
</resources> 

Hoạt động của tôi từ AndroidManifest.xml

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" 
    android:uiOptions="splitActionBarWhenNarrow" > 

Ai đó có thể cho tôi xin làm thế nào để mở rộng và sử dụng các chủ đề tùy chỉnh một cách chính xác.

Trả lời

4

cấu hình AndroidManifest.xml bạn để sử dụng một chủ đề tùy chỉnh:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    .... 
    <application 
     ... 
     android:theme="@style/AppTheme" 
     ... 
    > 
    ... 
    </application> 
    .... 
</manifest> 

Xác định Theme tùy chỉnh của bạn trong res/values/styles.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android"> 

    <!-- Use a custom Application theme extending an existing AppCompat theme. --> 
    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light"> 
    </style> 

    <!-- customize parts of your theme. --> 
    <style name="AppTheme" parent="AppBaseTheme"> 
     <!-- indicate that the actionBar uses a custom style and configure the link --> 
     <item name="actionBarTabStyle">@style/TabBarStyle</item> 
    </style> 

    <!-- configure your real custom style for the tab bar--> 
    <style name="TabBarStyle" parent="@style/Widget.AppCompat.ActionBar.TabView"> 
     <item name="android:paddingLeft">5dp</item> 
     <item name="android:paddingRight">5dp</item> 
     <item name="android:minWidth">10dp</item> 
     <item name="android:maxWidth">15dp</item> 
    </style> 

</resources> 

Sau đây nên được đặt trong res/values/styles-v11.xmlres/values/styles-v14.xml

<style name="AppTheme" parent="AppBaseTheme"> 
    <item name="actionBarTabStyle">@style/TabBarStyle</item> 
</style> 

<style name="TabBarStyle" parent="@style/Widget.AppCompat.ActionBar.TabView"> 
    <item name="android:paddingLeft">5dp</item> 
    <item name="android:paddingRight">5dp</item> 
    <item name="android:minWidth">10dp</item> 
    <item name="android:maxWidth">15dp</item> 
</style> 

Các vấn đề liên quan