Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android create a "flat button"

Supposedly, in the material theme, there are two types of buttons: raised, and flat:

Raised and Flat

When I create a <Button>, it looks like the "raised" button. How, using markup, can I make the "flat button". Is there any style or attribute to do it? I found this image in the theme editor.

like image 320
James Parsons Avatar asked Nov 10 '15 00:11

James Parsons


People also ask

What is flat button in Android?

FButton is a custom Button of Android with "Flat UI" concept. FButton's design get inspiration from designmono. This library is very small and highly customizable.

How can I make my Android button more attractive?

Using colors (background, text, border) Using custom shapes like circle, rounded corners and more. You can add images to your buttons to customize them. Using drawables to make gradients, dotted borders and more.

Can we change the shape of button in Android Studio?

We can set custom shapes on our button using the xml tag <shape> . These xml files are created in the drawable folder too. shape can be used inside selectors . The shape can be set to rectangle (default), oval , ring , line .


2 Answers

You can use the style="?android:attr/borderlessButtonStyle on your Button as follows:

<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextGoesHere" style="?android:attr/borderlessButtonStyle" /> 

BorderlessButtonStyle

Style for buttons without an explicit border, often used in groups.

Also you can use those Flat Buttons

like image 53
Skizo-ozᴉʞS Avatar answered Oct 04 '22 14:10

Skizo-ozᴉʞS


Add dependency to build.gradle

dependencies {     compile 'com.android.support:appcompat-v7:25.0.0' } 

Then in your layout XML file, add a style attribute to the Button

<Button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="Button"     style="@style/Widget.AppCompat.Button.Borderless"/> 

You can change the color when the button is pressed by defining a custom style

<style name="FlatButtonStyle" parent="Theme.AppCompat.Dark">     <item name="colorControlHighlight">@color/transparent</item> </style> 

and applying this style in layout XML

android:theme="@style/FlatButtonStyle" 
like image 39
pha Avatar answered Oct 04 '22 15:10

pha