Search code examples
androidandroid-viewandroid-buttonandroid-themeandroid-styles

Why button does not have material touch feedback?


I am working on android application and using material design.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.app.android">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".registration.RegistrationActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
    <item name="buttonStyle">@style/RobotoButtonStyle</item>

    <!-- to change back button color to white -->
    <item name="colorControlNormal">@android:color/white</item>
</style>

<style name="RobotoButtonStyle" parent="android:Widget.Holo.Button">
    <item name="android:fontFamily">@font/lato_medium</item>
</style>

activity_registration.xml

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingEnd="@dimen/default_view_padding_right"
    android:paddingStart="@dimen/default_view_padding_left"
    android:text="@string/registration_sign_up"
    android:textColor="@android:color/white"
    app:layout_constraintTop_toBottomOf="@id/til_registration_business_state" />

RegistrationActivity.kt

class RegistrationActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_registration)
    }
}

enter image description here

Does anyone know why material design background color and feedback color is not setting on button ?


Solution

  • You should use android:theme instead of android:style .

    At first Set your Button Parent parent="Base.Widget.AppCompat.Button

    Don't

    style="@style/RobotoButtonStyle"
    

    Do

    android:theme="@style/RobotoButtonStyle"
    

    Courtesy goes to Android Material Design Button Styles .

    For a specific button:

    If you need to change the style of a specific button, you can define a new style, inheriting one of the parent styles described above. In the example below I just changed the background and font colors:

    <style name="AppTheme.Button" parent="Widget.AppCompat.Button.Colored">
        <item name="colorButtonNormal">@color/Red</item>
        <item name="android:textColor">@color/White</item>
    </style>
    

    Then you just need to apply this new style on the button with:

    android:theme="@style/AppTheme.Button"