paris icon indicating copy to clipboard operation
paris copied to clipboard

Applying style for MaterialButton

Open filol opened this issue 4 years ago • 2 comments

I try to change the style of a button when the user clicks on it (like a checkbox works) but the result is not really what I expected. I'm using Kotlin and the last stable api for android material

Here is the xml :

<Button
                android:id="@+id/btn_distributor_2"
                style="@style/Widget.MaterialComponents.Button.OutlinedButton"
                android:layout_width="wrap_content"
                android:layout_height="48dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:text="@string/general_player2"
                android:textSize="12sp"
                app:layout_constraintBaseline_toBaselineOf="@+id/btn_distributor_1"
                app:layout_constraintLeft_toRightOf="@+id/btn_distributor_1"
                app:layout_constraintRight_toLeftOf="@+id/btn_distributor_3" />

My code :

 override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        viewModel = ViewModelProvider(this).get(AddTrickViewModel::class.java)
        

        btnsDistributor.forEach {
            it.setOnClickListener { view -> onClickDistributor(view) }
        }

    }

    private fun onClickDistributor(view: View) {
        view.style(R.style.Widget_MaterialComponents_Button)
    }

Before clic : image

After clic : image

What i expect: image

Have any idea why this doesn't work? As we can see something is happening the border changes but not as expected

filol avatar Feb 06 '21 14:02 filol

Had the same issue with custom styles. I have figured out that this is a problem with dot notation. Try to create custom style without dot notation and use it.

@elihart can u give some hint how to fix this?

Skullper avatar Sep 01 '21 13:09 Skullper

Tried creating a custom style definition with no dots and no parent="". Still not working. The button maintains the default styling applied by the theme and completely ignores the style applied.

rmirabelle avatar Mar 18 '22 17:03 rmirabelle