Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying style for MaterialButton #150

Open
filol opened this issue Feb 6, 2021 · 2 comments
Open

Applying style for MaterialButton #150

filol opened this issue Feb 6, 2021 · 2 comments

Comments

@filol
Copy link

filol commented Feb 6, 2021

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

@Skullper
Copy link

Skullper commented Sep 1, 2021

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?

@rmirabelle
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants