Android: изменить фон заголовка вкладки. - PullRequest
0 голосов
/ 30 июля 2011

Я хочу добавить селектор в заголовок вкладки (не тело вкладки), но без результатов.Может быть, у кого-то есть пример?

1 Ответ

0 голосов
/ 09 ноября 2011

Простой способ сделать это:

  1. Создание пользовательского макета:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="0dip"
        android:layout_height="64dip"    
        android:layout_weight="1"
        android:orientation="vertical"
        android:background="@drawable/tab_indicator"
        >
    
        <ImageView android:id="@+id/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:paddingTop="7dip"
        />
    
        <TextView android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            style="?android:attr/tabWidgetStyle"
            android:paddingBottom="5dip"
        />    
    </RelativeLayout>
    
  2. Добавьте вкладки, используя этот макет:

    private void addTab(String text, int drawable) {
        TabHost.TabSpec spec = mTabHost.newTabSpec(text);
    
        View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
    
        TextView title = (TextView) tabIndicator.findViewById(R.id.title);
        title.setText(text);
        ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
        icon.setImageResource(drawable);
    
        spec.setIndicator(tabIndicator);    
    
        mTabHost.addTab(spec.setContent(this));
    
    }
    
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...