Android - How to programmatically set the button style in a Linearlayout?

前端 未结 6 1795
无人共我
无人共我 2020-12-25 11:22

I am programmatically creating a LinearLayout for an AlertDialog with some buttons.

I WANT to do this:



        
6条回答
  •  Happy的楠姐
    2020-12-25 11:39

    In my case style was not loaded at all when I pass them into Button constructor. It seems that was because I was using the material design view. Here what solved my case:

    val themeWrapper = ContextThemeWrapper(
          context,
          R.style.AppTheme_ButtonPrimary // my button style
    )
    
    val button = MaterialButton(themeWrapper)
    

    Please note that MaterialButton was created instead of Button.

    I found this solution at: How to specify a style for a view programmatically in Android.

提交回复
热议问题