estoy usando pestañas en mi aplicación para Android, y me he encontrado con este problema cuando se ejecuta la aplicación en los teléfonos HTC Sense de Android:estilo personalizado para TabWidget
Android: Highlighted tab of TabWidget not readable on HTC Sense
La solución sugerida allí (ajuste de Android: targetSdkVersion to 4) no me soluciona el problema, ni tampoco quiero establecer el sdk objetivo en 4.
En su lugar, he intentado resolver este problema creando mi propio estilo de widget de pestañas y modificando el color del texto. El problema es que no hay diferencia notoria cuando uso mi propio estilo; es decir, el estilo no parece aplicarse a las pestañas.
Este es el código de la actividad principal, la celebración de las fichas:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Tab 1").setContent(new Intent(this, Tab1.class)));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Tab 2").setContent(new Intent(this, Tab2.class)));
tabHost.setCurrentTab(0);
}
Ésta es mi tab.xml. Tenga en cuenta que he especificado MyTabStyle como el estilo de TabWidget:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
style="@style/MyTabStyle"
android:id="@android:id/tabs"
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"
android:padding="5dp" />
</LinearLayout>
</TabHost>
Y esta es mi definición de MyTabStyle, que he definido en res/valores/styles.xml:
<style name="MyTabStyle" parent="@android:style/TextAppearance.Widget.TabWidget">
<item name="android:textColor">#5DFC0A</item>
</style>
¿Por qué no hay cambios en MyTabStyle aparece en mi aplicación? ¿Alguna otra solución para resolver el texto invisible en las pestañas seleccionadas en HTC Sense?
ACTUALIZACIÓN 2011-06-02
me las arreglé para resolver esto en una clase de manera hacky, utilizando el conocimiento de que el texto de los rótulos son en realidad TextViews. Agregue el método siguiente a su actividad:
private void setTabColor(TabHost tabHost) {
try {
for (int i=0; i < tabHost.getTabWidget().getChildCount();i++) {
TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); //Unselected Tabs
if (tv != null) {
tv.setTextColor(Color.parseColor("#ffffff"));
}
TextView tv2 = (TextView) tabHost.getCurrentTabView().findViewById(android.R.id.title); // Selected Tab
if (tv2 != null) {
tv2.setTextColor(Color.parseColor("#000000"));
}
}
} catch (ClassCastException e) {
// A precaution, in case Google changes from a TextView on the tabs.
}
}
Añadir lo siguiente en su método onCreate() en su actividad:
// Only apply the fix if this is a HTC device.
if (android.os.Build.MANUFACTURER.toLowerCase().contains("htc")) {
// Set up the color initially
setTabColor(tabHost);
// Add a tab change listener, which calls a method that sets the text color.
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(tabHost.getApplicationWindowToken(), 0);
setTabColor(tabHost);
}
});
}
Relacionado, pero no exactamente un duplicado, pero tiene una respuesta mejor (¿más reciente?) Sobre cómo diseñar el TabWidget: http://stackoverflow.com/a/2805256/2291 –