I want to remove the shadow from the button to make it seem more flat.
I have this right now:
But I want this:
Another alternative is to add
style="?android:attr/borderlessButtonStyle"
to your Button xml as documented here http://developer.android.com/guide/topics/ui/controls/button.html
An example would be
<Button
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage"
style="?android:attr/borderlessButtonStyle" />
Using this as the background for your button might help, change the color to your needs
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape android:shape="rectangle">
<solid android:color="@color/app_theme_light" />
<padding
android:left="8dp"
android:top="4dp"
android:right="8dp"
android:bottom="4dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/app_theme_dark" />
<padding
android:left="8dp"
android:top="4dp"
android:right="8dp"
android:bottom="4dp" />
</shape>
</item>
</selector>
the @Alt-Cat answer work for me!
R.attr.borderlessButtonStyle doesn't contain shadow.
and the document of button is great.
Also, you can set this style on your custom button, in second constructor.
public CustomButton(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.borderlessButtonStyle);
}
Instead of a Button, you can use a TextView and add a click listener in the java code.
I.e.
in the activity layout xml:
<TextView
android:id="@+id/btn_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:text="@string/btn_text"
android:gravity="center"
android:textColor="@color/colorAccent"
android:fontFamily="sans-serif-medium"
android:textAllCaps="true" />
in the activity java file:
TextView btnTextView = (TextView) findViewById(R.id.btn_text_view);
btnTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// handler code
}
});