Pregunta

I'd like to dynamically create buttons that look exactly like the buttons I create by declaring a widget "Button" in xml. This code:

Button myButton = new Button(getApplicationContext());
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(
                            ViewGroup.LayoutParams.MATCH_PARENT,
                            ViewGroup.LayoutParams.WRAP_CONTENT);
myButton.setText("dinamic");  //Integer.toString(i)
LinearLayout ll = (LinearLayout)findViewById(R.id.supbarL);
ll.addView(myButton, lp);

creates black weird-looking buttons... Is there a way to get and set the style of a view to be equal to a standard-looking widget or to another view? Also, where can I find the xml definitions of the different themes?

¿Fue útil?

Solución

Issue could be that you have set the base theme in manifest.

Try to change the theme to light/dark

Android with support library

 android:theme="@style/Theme.AppCompat.Light"  

Android without support library

android:theme="@style/Theme.Base.Light"
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top