vivaldi titulo theme tareas studio señal notificaciones name google ff0202 estado encabezado content como color chrome cambiar barra and android android-actionbar android-tabs

android - titulo - Cambiar las pestañas de la barra de acción subrayan el color mediante programación



cambiar el color de la barra de estado android studio (8)

He creado la barra de acción por

ActionBar actionbar = getActionBar()

El fondo de la barra de acción se cambia por

actionbar.setBackgroundDrawable(actionBarBackgroundImage);

Ahora necesito cambiar las pestañas de la barra de acción para subrayar el color mediante programación. ¿Hay algún método para cambiar el color del subrayado de las pestañas de la barra de acción?



Aquí hay una manera mucho más fácil. Sé que buscabas un cambio programático, pero este es REALMENTE fácil.

He estado luchando con esto durante días, pero finalmente encontré la solución. Estoy usando AppCompat. Puede establecer colorAccent en su tema y eso cambiará el color de resaltado en su barra de acción. Al igual que:

<item name="colorAccent">@color/highlightcolor</item>

Aquí está en contexto:

<style name="LightTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="colorPrimary">@color/darkgrey</item> <item name="colorPrimaryDark">@color/black</item> <item name="colorAccent">@color/highlightcolor</item> </style>

Donde originalmente publiqué esta respuesta: la pestaña de Android subraya el color no cambia


Consiguió la solución para cambiar el color del resaltador de pestañas después de un largo día de búsqueda. ¡Solo 2 líneas de código hacen que este trabajo sea perfecto!

Vaya a values ​​/ styles.xml y agregue el siguiente código en ActionBar Theme

<item name="colorAccent">@color/Tab_Highlighter</item>

Ahora da el color para Tab_Highlighter en colors.xml

<color name="Tab_Highlighter">#ffffff</color>


Consulte this , para personalizar la barra de acción,

<?xml version="1.0" encoding="utf-8"?> <resources> <!-- the theme applied to the application or activity --> <style name="CustomActivityTheme" parent="@android:style/Theme.Holo"> <item name="android:actionBarStyle">@style/MyActionBar</item> <!-- other activity and action bar styles here --> </style> <!-- style for the action bar backgrounds --> <style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar"> <item name="android:background">@drawable/ab_background</item> <item name="android:backgroundStacked">@drawable/ab_background</item> <item name="android:backgroundSplit">@drawable/ab_split_background</item> </style> </resources>


Probé muchas de las sugerencias publicadas aquí y otros lugares sin suerte. Pero creo que logré reconstruir una solución (aunque no perfecta).

El TabWidget está utilizando un selector. Esencialmente, muestra una imagen de 9 parches diferentes según el estado de la pestaña (seleccionada, presionada, etc.). Finalmente me di cuenta de que podrías generar un selector mediante programación. Comencé con los 9 parches generados desde http://android-holo-colors.com/ (color: # 727272, TabWidget: Sí).

El mayor problema fue establecer el color. Configurar el filtro de color no hizo nada. Entonces, terminé cambiando los colores de cada uno de los píxeles de la imagen de 9 parches dentro de un bucle.

... /** * <code>NinePatchDrawableUtility</code> utility class for manipulating nine patch resources. * * @author amossman * */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) public class NinePatchDrawableUtility { // Matches the colors in the supported drawables private static final int TAB_UNDERLINE_HIGHLIGHT_COLOR = 1417247097; private static final int TAB_UNDERLINE_COLOR = -8882056; private static final int TAB_PRESSED_COLOR = -2122745479; private Resources resources; public NinePatchDrawableUtility(Resources resources) { this.resources = resources; } /** * Create a <code>StateListDrawable</code> that can be used as a background for the {@link android.widget.TabWidget}</br></br> * * <code> * FragmentTabHost tabHost = ...</br> * NinePatchUtility ninePatchUtility = new NinePatchUtility(getResources());</br> * TabWidget tabWidget = tabHost.getTabWidget();</br> * for (int i = 0; i < tabWidget.getChildCount(); i++) {</br> * &nbsp;&nbsp;&nbsp;tabWidget.getChildAt(i).setBackground(ninePatchUtility.getTabStateListDrawable(titleColor));</br> * } * </code> * * @param tintColor The color to tint the <code>StateListDrawable</code> * @return A new <code>StateListDrawable</code> that has been tinted to the given color */ public StateListDrawable getTabStateListDrawable(int tintColor) { StateListDrawable states = new StateListDrawable(); states.addState(new int[] {android.R.attr.state_pressed}, changeTabNinePatchColor(resources, R.drawable.cc_tab_selected_pressed_holo, tintColor)); states.addState(new int[] {android.R.attr.state_focused}, changeTabNinePatchColor(resources, R.drawable.cc_tab_selected_focused_holo, tintColor)); states.addState(new int[] {android.R.attr.state_selected}, changeTabNinePatchColor(resources, R.drawable.cc_tab_selected_holo, tintColor)); states.addState(new int[] { }, changeTabNinePatchColor(resources, R.drawable.cc_tab_unselected_holo, tintColor)); return states; } /** * Change the color of the tab indicator.</br></br> * * Supports only the following drawables:</br></br> * * R.drawable.cc_tab_selected_pressed_holo</br> * R.drawable.cc_tab_selected_focused_holo</br> * R.drawable.cc_tab_selected_holo</br> * R.drawable.cc_tab_unselected_holo</br></br> * * Note: This method is not efficient for large <code>Drawable</code> sizes. * * @param resources Contains display metrics and image data * @param drawable The nine patch <code>Drawable</code> for the tab * @param tintColor The color to tint the <code>Drawable</code> * @return A new <code>NinePatchDrawable</code> tinted to the given color */ public NinePatchDrawable changeTabNinePatchColor(Resources resources, int drawable, int tintColor) { int a = Color.alpha(tintColor); int r = Color.red(tintColor); int g = Color.green(tintColor); int b = Color.blue(tintColor); BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inMutable = true; Bitmap bitmap = BitmapFactory.decodeResource(resources, drawable, opt); for (int x = 0; x < bitmap.getWidth(); x++) { for (int y = 0; y < bitmap.getHeight(); y++) { int color = bitmap.getPixel(x, y); if (color == TAB_PRESSED_COLOR) { bitmap.setPixel(x, y, Color.argb((int)(a * 0.5), r, g, b)); } else if (color == TAB_UNDERLINE_HIGHLIGHT_COLOR) { bitmap.setPixel(x, y, Color.argb((int)(a * 0.9), r, g, b)); } else if (color == TAB_UNDERLINE_COLOR) { bitmap.setPixel(x, y, tintColor); } } } return new NinePatchDrawable(resources, bitmap, bitmap.getNinePatchChunk(), new Rect(), null); } }

Ejemplo de uso:

/** * Theme the tab widget with the defined background color and title color set * in the TabManager * @param tabWidget */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public void theme(TabWidget tabWidget) { ColorDrawable backgroundDrawable = new ColorDrawable(backgroundColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { tabWidget.setBackground(backgroundDrawable); tabWidget.setAlpha(0.95f); } else { backgroundDrawable.setAlpha(242); tabWidget.setBackgroundDrawable(backgroundDrawable); } NinePatchDrawableUtility ninePatchUtility = new NinePatchDrawableUtility(resources); for (int i = 0; i < tabWidget.getChildCount(); i++) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { tabWidget.getChildAt(i).setBackground(ninePatchUtility.getTabStateListDrawable(titleColor)); } else { tabWidget.getChildAt(i).setBackgroundDrawable(ninePatchUtility.getTabStateListDrawable(titleColor)); } View tabView = tabWidget.getChildTabViewAt(i); tabView.setPadding(0, 0, 0, 0); TextView tv = (TextView) tabView.findViewById(android.R.id.title); tv.setSingleLine(); // set the texts on the tabs to be single line tv.setTextColor(titleColor); } }


Puedes usar este código:

actionBar.setStackedBackgroundDrawable(new ColorDrawable(yourColor));


intenta seguir

escriba tabs_selector_green.xml en res / drawable.

<!-- Non focused states --> <item android:drawable="@android:color/transparent" android:state_focused="false" android:state_pressed="false" android:state_selected="false"/> <item android:drawable="@drawable/layer_bg_selected_tabs_green" android:state_focused="false" android:state_pressed="false" android:state_selected="true"/> <!-- Focused states --> <item android:drawable="@android:color/transparent" android:state_focused="true" android:state_pressed="false" android:state_selected="false"/> <item android:drawable="@drawable/layer_bg_selected_tabs_green" android:state_focused="true" android:state_pressed="false" android:state_selected="true"/> <!-- Pressed --> <!-- Non focused states --> <item android:drawable="@android:color/transparent" android:state_focused="false" android:state_pressed="true" android:state_selected="false"/> <item android:drawable="@drawable/layer_bg_selected_tabs_green" android:state_focused="false" android:state_pressed="true" android:state_selected="true"/> <!-- Focused states --> <item android:drawable="@android:color/transparent" android:state_focused="true" android:state_pressed="true" android:state_selected="false"/> <item android:drawable="@drawable/layer_bg_selected_tabs_green" android:state_focused="true" android:state_pressed="true" android:state_selected="true"/>

escriba layer_bg_selected_tabs_green.xml en la carpeta res / drawable.

<item> <shape android:shape="rectangle" > <solid android:color="@color/tab_green" /> <padding android:bottom="5dp" /> </shape> </item> <item> <shape android:shape="rectangle" > <solid android:color="#FFFFFF" /> </shape> </item>

y en código java escribo esto.

private static final int[] TABS_BACKGROUND = { R.drawable.tabs_selector_orange, R.drawable.tabs_selector_green, R.drawable.tabs_selector_red, R.drawable.tabs_selector_blue, R.drawable.tabs_selector_yellow }; /* BLA BLA BLA */ @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub RelativeLayout tabLayout = (RelativeLayout) tab.getCustomView(); tabLayout.setBackgroundResource(TABS_BACKGROUND[tab.getPosition()]); tab.setCustomView(tabLayout); /* ... */ }


Te sugiero que uses ActionBarSherlock . Hay una muestra disponible en la biblioteca llamada "Style ActionBar". (esta es la única forma en que puede cambiar las pestañas de la barra de acción subrayando el color)

Si ha personalizado ActionBar, debe agregar este estilo en ActionBar Style.

o aquí es cómo hacer esto

cree un estilo como el de abajo (aquí he usado ActionBarShareLock si no quiere usarlo, use android-support-v4.jar para soportar todas las versiones del sistema operativo Android)

<style name="Theme.AndroidDevelopers" parent="Theme.Sherlock.Light"> <item name="android:actionBarTabStyle">@style/MyActionBarTabStyle</item> <item name="actionBarTabStyle">@style/MyActionBarTabStyle</item> </style> <!-- style for the tabs --> <style name="MyActionBarTabStyle" parent="Widget.Sherlock.Light.ActionBar.TabBar"> <item name="android:background">@drawable/actionbar_tab_bg</item> <item name="android:paddingLeft">32dp</item> <item name="android:paddingRight">32dp</item>

actionbar_tab_bg.xml

<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/ad_tab_unselected_holo" /> <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/ad_tab_selected_holo" /> <item android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/ad_tab_selected_pressed_holo" /> <item android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/ad_tab_selected_pressed_holo" />

Reproduce este estilo en tu actividad en el archivo de manifiesto de Android

<activity android:name="com.example.tabstyle.MainActivity" android:label="@string/app_name" android:theme="@style/Theme.AndroidDevelopers" >

Para más detalles revisa esta answer y este article .

EDITADO: 29-09-2015

ActionBarSherlock está en desuso, por lo que alternativamente puede usar la biblioteca de soporte de design Android y la biblioteca de aplicaciones de appcompat para TOOLBAR (Action-Bar está en desuso así que) y TABS.

usa TabLayout como abajo

<android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabGravity="center" app:tabMode="scrollable" app:tabSelectedTextColor="@color/white" app:tabIndicatorColor="@color/colorPrimary" app:tabIndicatorHeight="2dip" app:tabTextAppearance="?android:attr/textAppearanceMedium" app:tabTextColor="@color/colorAccent" />

Aquí está una muestra de la biblioteca de soporte de diseño de Android con pestaña