
Problemas new Handler().post()
Publicado por karrax (9 intervenciones) el 10/01/2016 12:13:27
Hola:
Estoy intentando cambiar el color de fondo del menu y para ello he encontrado el siguiente codigo:
En este codigo me sale un error en la parte del.
¿Cual puede ser el problema?
Muchas gracias
Estoy intentando cambiar el color de fondo del menu y para ello he encontrado el siguiente codigo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
protected void setMenuBackground(){
// Log.d(TAG, "Enterting setMenuBackGround");
getLayoutInflater().setFactory( new Editable.Factory() {
public View onCreateView(String name, Context context, AttributeSet attrs) {
if ( name.equalsIgnoreCase( "com.android.internal.view.menu.IconMenuItemView" ) ) {
try { // Ask our inflater to create the view
LayoutInflater f = getLayoutInflater();
final View view = f.createView( name, null, attrs );
/* The background gets refreshed each time a new item is added the options menu.
* So each time Android applies the default background we need to set our own
* background. This is done using a thread giving the background change as runnable
* object */
new Handler().post( new Runnable() {
public void run () {
// sets the background color
view.setBackgroundColor(Color.parseColor("#6296be"));
// sets the text color
((TextView) view).setTextColor(Color.WHITE);
// sets the text size
((TextView) view).setTextSize(18);
}
} );
return view;
}
catch ( InflateException e ) {}
catch ( ClassNotFoundException e ) {}
}
return null;
}});
}
En este codigo me sale un error en la parte del
1
new Handler().post(...
¿Cual puede ser el problema?
Muchas gracias
Valora esta pregunta


0