Material Design Button without Shadow - android

I recently started android development and I am struggling a bit.
I read different articles and tutorials on creating drawables etc.
Current Situation
I have created the following buttons:
Using the following code:
<android.support.v7.widget.AppCompatButton
android:id="#+id/login_btn_facebook"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:drawableStart="#drawable/ic_btn_login_facebook"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Continue with Facebook"
android:textColor="#fff"
app:backgroundTint="#3b5998"/>
<android.support.v7.widget.AppCompatButton
android:id="#+id/login_btn_google"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:drawableStart="#drawable/ic_btn_login_google"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="Continue with Google"
app:backgroundTint="#ffffff" />
Now I actually just need a minor change:
I do not want to have the elevation. I want the buttons to be "flat", and only show the shadow effect when clicked.
Is there a simple way to do this?
Thank you already!
UPDATE:
I need to target API Level 19 as a minimum SDK version.

You have two alternatives to do that:
By adding an XML attribute to your XML Button:
Try this: android:stateListAnimator="#null"
By adding another XML attribute, if the previous alternative has not worked:
Add this style="?android:attr/borderlessButtonStyle" to your XML Button according this.
Let me know if it doesn't work!

Add the following attributes in your layout XML to remove shadows:
android:elevation="0dp"
android:translationZ="0dp"
This will make your layout look like:
<android.support.v7.widget.AppCompatButton
android:id="#+id/login_btn_facebook"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:drawableStart="#drawable/ic_btn_login_facebook"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:elevation="0dp"
android:translationZ="0dp"
android:text="Continue with Facebook"
android:textColor="#fff"
app:backgroundTint="#3b5998"/>
<android.support.v7.widget.AppCompatButton
android:id="#+id/login_btn_google"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:drawableStart="#drawable/ic_btn_login_google"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:elevation="0dp"
android:translationZ="0dp"
android:text="Continue with Google"
app:backgroundTint="#ffffff" />
Read here for more information.

Related

Android studio different layout on emulator

I just started using android studio and I inserted a button and text field. In preview panel looks ok but when I run the app the layout it's different.
This is the xml code:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
tools:context="com.example.alexander.myapplication.MainActivity">
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
tools:ignore="HardcodedText" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="119dp"
tools:layout_editor_absoluteY="222dp"
tools:ignore="HardcodedText,MissingConstraints"
android:onClick="buttonClicked"
/>
This is how it looks like
Thank you!
Look at the lines:
tools:layout_editor_absoluteX="119dp"
tools:layout_editor_absoluteY="222dp"
What they say is that you placed the button in an absolute position BUT only in the editor preview.
The button doesn't have real placement values when the app actually running (notice the "editor" prefix in the parameters name).
You need to define actual values in the editor.
Check out this guide on the Android developers site:
Build a Responsive UI with ConstraintLayout
I just solved the problem by setting the layout to RelativeLayout.

GUI elements not displaying properly

I was following along some Android tutorial on Youtube when I encountered the following problem:
(left the designer, right the emulator)
I tried searching on google, but can't seem to find the right link.
Does anyone have any idea what is going on? I tried deleting and placing new elements, but the same problem keeps occurring.
[Edit]
XML code which I didn't change. This was created with a new project.
All elements in the picture were dragged and dropped. No code was changed.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
tools:context="com.example.todor.myapplication.MainActivity">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="159dp"
tools:layout_editor_absoluteY="235dp"
tools:text="#string/loginbutton" />
<TextView
android:id="#+id/textView2"
android:layout_width="132dp"
android:layout_height="31dp"
android:layout_marginBottom="42dp"
android:fontFamily="monospace"
android:textAlignment="center"
android:textColor="#color/colorAccent"
android:textColorHint="#android:color/holo_blue_bright"
android:textStyle="bold"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="#+id/editText"
tools:text="#string/logintext"
tools:layout_editor_absoluteX="126dp" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="33dp"
android:width="300dp"
android:ems="10"
android:hint="#string/emailhint"
android:inputType="textEmailAddress"
app:layout_constraintBottom_toTopOf="#+id/editText2"
tools:layout_editor_absoluteX="42dp" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
android:width="300dp"
android:ems="10"
android:hint="#string/passowrdhint"
android:inputType="textPassword"
app:layout_constraintBottom_toTopOf="#+id/button"
tools:layout_editor_absoluteX="42dp" />
</android.support.constraint.ConstraintLay
out>
Here are some tips for you !
Read about Tools Attributes Reference
Android Studio supports a variety of XML attributes in the tools namespace that enable design-time features (such as which layout to show in a fragment) or compile-time behaviors (such as which shrinking mode to apply to your XML resources). When you build your app, the build tools remove these attributes so there is no effect on your APK size or runtime behavior.
You need to understand the difference of below attributes!
tools:text="loginbutton"
android:text="loginbutton"
Your views are not constrained they have only design time position!
Go to the design, drag the corners until the circle turns green and then give the constraint.Here is an extra guidance from linkOne LinkTwo related with ConstraintLayout
If you mess it up big-time you can replace android.support.constraint.ConstraintLayout with LinearLayout but that's not the solution it's another way instead!

Remove Shadow in GeocoderAutoCompleteView - Mapbox

How do I remove the border shadow in:
com.mapbox.services.android.geocoder.ui.GeocoderAutoCompleteView
Could you provide your XML for the geocoder? The geocoding widget extends EditText therefore, you should be able to change the styling similar to an edittext. In the demo app the xml for the widget looks like this:
<com.mapbox.services.android.geocoder.ui.GeocoderAutoCompleteView
android:id="#+id/query"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="18dp"
android:layout_marginStart="18dp"
android:layout_marginTop="14dp"
android:background="#android:color/white"
android:elevation="12dp"
android:hint="Search Location"
android:padding="10dp"
android:singleLine="true"
android:textColor="#android:color/black"/>
removing the android:elevation="12dp" removes the "shadow".
on a side note, from the screenshot above, the shadow actually looks pretty good ;)

Android: Making EditText similar to Chrome's URL box

I'm making chatting application for my school's assignment.
In my opinion, the default EditText in Android does not looks good. I want to make it looks like the URL box in Android's Chrome:
I have seen this design used in other applications such as Catch Notes (which looks beautiful).
So, is there any built-in option to change the EditText or we must draw it from scratch? Can anyone give link? I tried googling it, but I don't know the correct term
Thanks
you can achieving this by doing edittext background transparent.
so put your image in background of your layout and take a edittext inside this. and make edittext transpernt..
or
try this
<EditText
android:id="#+id/tracknumbertxt"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_toLeftOf="#+id/info"
android:background="#drawable/enter_tracking_no"
android:ems="10"
android:hint="Enter Tracking No."
android:paddingLeft="30dp"
android:inputType="text"
android:imeOptions="actionGo"
android:singleLine="true" >
</EditText>
here i have assign padding left..
so as per your design you have to set paddingRight property instead of paddingLeft..
Blindly use below layout style..
You will have your layout ready. Just replace the button backgrounds and your are done.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#android:color/darker_gray"
android:padding="5dip"
android:gravity="center">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
android:background="#android:color/white"
android:gravity="center"
android:padding="5dip">
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Type URL"
android:layout_weight="1"
android:background="#android:color/transparent"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Refresh"/>
</LinearLayout>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn1"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn2"/>
</LinearLayout>
There is nothing native to the SDK that can make it look like that. (maybe if you restrict use to only a certain version of the OS, then you can use that version's default styling, but isn't really a viable solution)
You will need to create an image to use as a background for the EditText to make it look how you want. The best options for text boxes and things like that are to either use a 9-patch image, or to create a layer-list XML file and describe your design that way. Either way, the file would go in the res/drawable folder in the project and you would set it as the background like so:
<EditText android:id="#+id/et_whatever"
android:layout_width="match_parent"
android:layout_height="wrap_content"
background="#drawable/YOUR_FILE_NAME" />

Android borderless buttons

I hate to be the third person to ask this, but the previous two askings haven't seemed to answer it fully. The android design guidelines detail borderless buttons, but not how to make them. In one of the previous answers, there was a sugestion to use:
style="#android:style/Widget.Holo.Button.Borderless"
This works well for a Holo theme, but I use a lot of Holo.Light as well and
style="#android:style/Widget.Holo.Light.Button.Borderless"
Does not seem to exist. Is there a way to apply a style for such borderless buttons in Holo.Light, or better yet, simply apply a borderless tag without specifying which theme it belongs in, so the app can pick the proper style at runtime?
Holo.ButtonBar seems to fit the bill for what I am looking for, except it provides no user feedback that it's been pressed.
Also, is there a place in the documentation that lists such styles that can be applied and a description of them? No matter how much I google, and search through the docs, I can't find anything. There is just a non-descriptive list if I right click and edit style.
Any help would be appreciated.
Edit: Got a perfect answer from javram, and I wanted to add some XML for anyone interested in adding the partial borders google has adopted.
Fora horizontal divider, this works great
<View
android:id="#+id/horizontal_divider_login"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="#color/holo_blue" />
and this for a vertical one:
<View
android:id="#+id/vertical_divider"
android:layout_width="1dip"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#color/holo_blue" />
Simply add the following style attribute in your Button tag:
style="?android:attr/borderlessButtonStyle"
source: http://developer.android.com/guide/topics/ui/controls/button.html#Borderless
Check out my answer here. In a nutshell the correct solution is to use the following:
android:background="?android:attr/selectableItemBackground"
At the risk of beating a dead horse, here's another (possibly better) option. AppCompat v7 defines a borderless button style. If you're already making use of the AppCompat library, just go with that:
<Button android:text="#string/borderlessButtonText" style="#style/Widget.AppCompat.Button.Borderless" />
This code will remove all background for a button:
android:background="#android:color/transparent"
Just incase anybody is looking for light-weight solution to get the borderless button for the API's that do not support the Holo theme (like I did for a long time), Im posting my solution below:
<View
android:layout_height="1dp"
android:layout_width="match_parent"
android:background="#505154"
android:layout_marginLeft="10dp" android:layout_marginRight="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btn_Reply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#android:color/transparent"
android:paddingBottom="15dp" android:paddingTop="15dp"
android:textColor="#5c5966"
android:text="#string/btnReplyText"/>
<View
android:layout_height="fill_parent"
android:layout_width="1dp"
android:background="#505154"
android:layout_marginBottom="7dp" android:layout_marginTop="7dp"/>
<Button
android:id="#+id/btn_Delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:paddingBottom="15dp" android:paddingTop="15dp"
android:textColor="#5c5966"
android:background="#android:color/transparent"
android:text="#string/btnDeleteText" />
<View
android:layout_height="fill_parent"
android:layout_width="1dp"
android:background="#505154"
android:text="#string/btnReplyText"
android:layout_marginBottom="7dp" android:layout_marginTop="7dp" />
<Button
android:id="#+id/btn_Exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:text="#string/btnExitText"
android:paddingBottom="15dp" android:paddingTop="15dp"
android:textColor="#5c5966"
android:background="#android:color/transparent"/>
</LinearLayout>
All you have to do is change the colours and text to suit your own background. All the best!

Categories

Resources