Issue
I can't figure out why my buttons doesn't have the press effect. i guess my styles is the problem. The button is displayed inside a fragment hosted by AppCombatActivity
v21 style.xml is
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<style name="MyTheme" parent="MyTheme.Base">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
</style>
</resources>
style.xml is
<style name="MyTheme" parent="MyTheme.Base">
</style>
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Your customizations go here -->
<item name="buttonStyle">@style/LoginButton</item>
<!-- Override the color of UI controls -->
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:textColorSecondary">@color/white</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="colorPrimary">@color/my_blue</item>
<item name="colorPrimaryDark">@color/my_blue</item>
<item name="colorAccent">@color/my_purple</item>
</style>
<style name="LoginButton" parent="Widget.AppCompat.Button.Colored">
<item name="android:textAllCaps">false</item>
<item name="colorControlHighlight">@color/my_purple</item>
<item name="android:textColor">@color/white</item>
</style>
button code:
<Button
android:theme="@style/LoginButton"
android:background="@drawable/roundedbutton_do_this"
android:backgroundTint="@color/dark_blue"
android:id="@+id/SelectDateButton"
android:layout_width="match_parent"
android:layout_height="52dp"
android:gravity="center"
android:text="@string/ChooseDateTime_SelectDate"
android:layout_margin="12dp"
android:singleLine="false"
android:layout_gravity="center_vertical" />
background code:
<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/green"/>
<corners android:radius="10dp" />
</shape>
minSdkVersion:16
targetSdkVersion:27
Now i don't see any effect on the button when i press it. test it on android 6 and 7
EDIT: i have try this but the buttons dont have shape (rounded corners)
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:drawable="@color/green" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/gradient" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/gradient" />
<item android:drawable="@color/green" />
<item>
<shape android:shape="rectangle">
<solid android:color="@color/green"/>
<corners android:radius="10dp" />
</shape>
</item>
</selector>
Solution
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
app:cardCornerRadius="@dimen/_3sdp"
app:cardBackgroundColor="@android:color/white">
Answered By - Mohamed Fiyaz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.