0

We use this function to add buttons to our activity:

 private void createButtonListInLayout(Cursor c) {
    if (c.moveToFirst()) {
        do {
            Button button = new Button(this);
            button.setText(c.getString(DBAdapter.COL_TABLE_NAME_MAIN));
            linearLayoutList.addView(button);
        } while(c.moveToNext());
    }
}

I am trying to give these buttons a custom style. I've addded a buttonstyle to my apptheme, as you can see below, but the buttons created using the function above don't have this style.

This is the style I am trying to give to my buttons using my styles.xml file:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColor">@color/colortext</item>
    <item name="android:titleTextStyle">@color/colortext</item>
    <item name="buttonStyle">@style/AppTheme.button</item>
</style>

<style name="AppTheme.button" parent="Widget.AppCompat.Button.Borderless" >
    <item name="android:maxHeight">50dp</item>
    <item name="android:maxWidth">200dp</item>
    </style>

The buttons which are created by the first function don't have the style I want them to have. The other buttons (which are defined in the activity.xml files) do have the style. How can I make the buttons, which are created using the function above, the style I defined in the styles.xml file? Or is there another way to change the style of those buttons?

Cœur
  • 37,241
  • 25
  • 195
  • 267

0 Answers0