9

私はこのレイアウトで ActionBar.Tab setCustomView() メソッドを使用しています:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/background_grey" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="Test Tab" 
        android:textColor="@color/background_dark_green"/>

</RelativeLayout>

これは、ActionBar を設定する私の関数です。

public void setActionBar()
{
    ActionBar actionBar = getSupportActionBar();
    //actionBar.hide();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);        
    //set action bar navigation mode
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);        
    //set tabs      
    //home tab 
    Tab tab = actionBar.newTab().setText(TAB_HOME).setTabListener(new PicoTabListener<StartFragment>(this, StartFragment.class));       
    tab.setCustomView(R.layout.tab_background);
    actionBar.addTab(tab);
    //events tab
    tab = actionBar.newTab().setText(TAB_EVENTS).setTabListener(new PicoTabListener<EventsFragment>(this, EventsFragment.class));
    actionBar.addTab(tab);      
    //enter event code
    tab = actionBar.newTab().setText(TAB_CODE).setTabListener(new PicoTabListener<EnterCodeFragment>(this, EnterCodeFragment.class));
    actionBar.addTab(tab);      
}

と私の活動のレイアウト:

<?xml version="1.0" encoding="utf-8"?>
<!-- This is the main layout of the application -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_basic_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/background_dark_green" >

</RelativeLayout>

結果の継ぎ目は次のようになります (背景が灰色の左上のタブ)。 ここに画像の説明を入力

カスタムビューを作成してタブ全体を埋め、適切に機能させるにはどうすればよいですか?

Android 2.3 のサポート パッケージ v7 を使用しています

4

4 に答える 4

0

それでも問題が解決しない場合は、スペース全体を取得する方法を見つけました: ActionBar Tab with custom View not centered

于 2014-03-03T10:57:12.170 に答える
0

actionbarcompat の setCustomView を扱うときはandroid:margin、それに依存する必要がありますandroid:padding

ルート要素のパディング、幅、高さ、およびマージンが無視されるように見えることに注意してください。

于 2013-12-13T20:02:16.543 に答える