Android 如何将样式应用于onTabChanged中TabHost的选项卡?
有一个Android 如何将样式应用于onTabChanged中TabHost的选项卡?,android,Android,有一个选项卡host: <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/onglets" android:layout_width="fill_parent" android:layout_height="fill_parent" >
选项卡host
:
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/onglets"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include
android:id="@+id/contentOnglet1"
layout="@layout/parcelle"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<include
android:id="@+id/contentOnglet2"
layout="@layout/liste_modele"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</LinearLayout>
</TabHost>
模板选项卡\u onglets.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:id="@+id/tabLabel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:paddingTop="@dimen/paddingTitre"
android:paddingBottom="@dimen/paddingTitre"
android:background="@drawable/contour_tab_onglet"
android:textColor="@color/txt_color"
/>
</LinearLayout>
在TabHost
的onTabChangedListener
中,我想对TextView
tabLabel应用样式,例如粗体样式。怎么做?这是方法
mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabName) {
Log.i("***Selected Tab", "Im currently in tab with index::" + tabHost.getCurrentTab());
View v=tabHost.getCurrentTabView();
TextView title2 = (TextView) v.findViewById(R.id.tabLabel);
title2.setTypeface(Typeface.DEFAULT_BOLD);
}
});
mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabName) {
Log.i("***Selected Tab", "Im currently in tab with index::" + tabHost.getCurrentTab());
View v=tabHost.getCurrentTabView();
TextView title2 = (TextView) v.findViewById(R.id.tabLabel);
title2.setTypeface(Typeface.DEFAULT_BOLD);
}
});