I am trying to move the arrow button the the right side so it wont be in my text
any one can help me??
Button
this is the style code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<padding android:right="10dp"/>
</shape>
</item>
<item>
<bitmap android:src="#drawable/style" android:gravity="center|right"/>
</item>
</layer-list>
</item>
</selector>
I tried to change gravity but it wont work
Hey you can use material design button that will helpful
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:iconGravity="end"
android:background="#android:color/white"
android:backgroundTint="#android:color/white"
android:text="A+20"
app:icon="#drawable/ic_baseline_arrow_forward_24"
style="#style/Widget.MaterialComponents.Button.TextButton.Icon"
/>
source: https://material.io/components/buttons/android#text-button
Related
I have the following code for an oval button and am attempting to add a black shadow to it. I first implemented an oval button and it worked as desired, when I added the <layered-list> it ends up being a completely black oval with the first item not showing on any layers. Any help to make it act as a shadow and appear in layers would be appreciated.
button_round.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape android:shape="oval">
<solid android:color="#color/colorLightGreen"/>
<size android:width="90dp" android:height="90dp"/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#color/colorShadowDark"/>
<size android:width="150dp" android:height="150dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>
layout\activity_main.xml:
<Button
android:id="#+id/start_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_round"
android:onClick="startNumberGuessing"
android:text="#string/startNGString"
app:elevation="10dp"
app:layout_constraintBottom_toTopOf="#+id/textView"
app:layout_constraintEnd_toStartOf="#+id/imageView"
app:layout_constraintStart_toEndOf="#+id/imageView"
app:layout_constraintTop_toBottomOf="#+id/textView"
app:layout_constraintVertical_bias="0.714" />
Don't use a shape on your button to this, instead use FloatingActionButton
The following code shows how the FloatingActionButton should appear in your layout file:
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="#drawable/ic_my_icon"
android:layout_margin="16dp" />
FloatingActionButton has a oval format and a shadow by default
I hope that help you!
Place light green oval after shadow oval in <layer-list> and use padding to make the shadow oval visible.
Below is the xml code that you can use as its solution.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape android:shape="oval">
<solid android:color="#color/colorShadowDark" />
<padding android:bottom="15dp" android:left="15dp" android:right="15dp" android:top="15dp" />
<size android:width="200dp" android:height="200dp" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#color/colorLightGreen" />
</shape>
</item>
</layer-list>
</item>
</selector>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="40dp"
card_view:cardElevation="3dp"
card_view:cardCornerRadius="2dp"
card_view:cardBackgroundColor="#fff">
you can use card view as a button, by increasing the cardCornerRadius size the corner will be rounded and the cardElevation maintain the shadow of the card.
before using card view please add dependency(use the latest version of dependency)
implement 'com.android.support:cardview-v7:23.3'
this answer may help you to create oval button.
I have created a custom circular button using the following :
<Button
android:id ="#+id/StartButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:background="#drawable/button_bg_round"
android:padding="15dp"
android:textSize="30sp"
android:textStyle="bold"
android:textColor="#ffffff"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
Here button_bg_round is defined as below :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:color="#ffffff" android:width="5dp" />
<solid android:color="#3aeaee"/>
<size android:width="200dp" android:height="200dp"/>
</shape>
</item>
</selector>
Now, I want to add a circular ripple/pulse effect/animation when the button is clicked. I tried to look for a possible solution on google and SO but couldn't find any related to such a button. Any help would be much appreciated.
You can make you drawable like this:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#color/colorAccent"
tools:targetApi="lollipop"> <!-- ripple effect color -->
<item android:id="#android:id/background">
<shape android:shape="oval">
<stroke android:color="#ffffff" android:width="5dp" />
<solid android:color="#3aeaee"/>
<size android:width="200dp" android:height="200dp"/>
</shape>
</item>
</ripple>
where android:color inside ripple is the color of the effect.
How can I design my EditText and Button like in the Instagram application? I understand that I would need to do this by using Drawable files but every link I have found only shows how to design using Gradients which looks horrible. I just want something simple but not sure where to start.
All you need to do is create a Button or Edittext or TextView with transparent background and colored border like:
activity code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorpink">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Transparent Button with blue border"
android:id="#+id/button"
android:padding="10dp"
android:layout_gravity="center_horizontal"
android:background="#drawable/transparent_button_selector"
android:textColor="#color/colorPrimary"
android:textAllCaps="false"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
transparent_button_selector.xml :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- pressed state -->
<item android:state_pressed="true"><shape>
<solid android:color="#android:color/transparent" />
<stroke android:width="2dp" android:color="#color/colorPrimary" />
<corners android:radius="22dp" />
</shape></item>
<!-- focused state -->
<item android:state_focused="true"><shape>
<solid android:color="#android:color/transparent" />
<stroke android:width="2dp" android:color="#color/colorPrimary" />
<corners android:radius="22dp" />
</shape></item>
<!-- normal state -->
<item><shape>
<solid android:color="#android:color/transparent"/>
<stroke android:width="2dp" android:color="#color/colorPrimary" />
<corners android:radius="22dp" />
</shape></item>
</selector>
colors :
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorpink">#AAFF4081</color>
And its looking like :
You can change transparent_button_selector.xml , change colors, radius values, borders and try to create your layout firstly and then think about background. Yes i will say gradient too . There is one question here for it : changing-gradient-background-colors-on-android-at-runtime
Also you can play with backgorund color, if you use few transparent white like #33FFFFFF then the result will be like : http://imgur.com/poGN2nn
It looks like they are using a single gradient drawable for the background of the login layout and then the EditTexts have a mostly-transparent white background and the Button has a fully transparent background. To round the corners of the EditText/Button, set the background to a drawable that looks something like this:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#android:color/transparent"/>
<corners
android:bottomRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:topLeftRadius="2dp"
android:topRightRadius="2dp"/>
</shape>
may be this code can help you. This is the activity.xml file. use TextView as Button.
<?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="match_parent"
android:orientation="vertical"
android:background="#FF929999">
<EditText
android:id="#+id/userName"
android:layout_width="fill_parent"
android:layout_height="48.0dip"
android:layout_marginBottom="16.0dip"
android:background="#drawable/input_field"
android:hint="username"
android:inputType="textNoSuggestions"
android:paddingLeft="16.0dip"
android:paddingRight="16.0dip"
android:singleLine="true"
android:textColor="#color/white"
android:textColorHint="#b3ffffff"
android:textCursorDrawable="#null"/>
<TextView
android:id="#+id/saveButton"
android:layout_width="match_parent"
android:layout_height="48.0dip"
android:background="#drawable/button_border"
android:gravity="center"
android:text="Save"
android:textColor="#ccffffff"
android:textSize="16sp"
android:textStyle="bold"/>
</LinearLayout>
input_field.xml file should look like this:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#1affffff"/>
<corners android:radius="2.0dip"/>
</shape>
And button_border.xml will be like this:
<?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="#1affffff"/>
<stroke
android:width="1.0dip"
android:color="#80ffffff"/>
<corners android:radius="2.0dip"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#00000000"/>
<stroke
android:width="1.0dip"
android:color="#33ffffff"/>
<corners android:radius="2.0dip"/>
</shape>
</item>
enjoy the design.
Use Drawable with border and transparent color for EditText and Button, and the entire violet background is image, not gradient drawable. And also use TransitionDrawable for transitioning between two drawables like Instagram.
I'd like to create the following custom EditText. How to make the vertical bar like the one on the picture?
Style edittext_custom_style.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#75d0e2" />
</shape>
</item>
<item android:left="5dp">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
xml:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edittext_custom_style"/>
Create same bar drawable and assign drawableLeft to edittext
Code put image in respective drawables like drawable-xhdpi etc
Sample is here.
<EditText
android:id="#+id/password"
style="#style/inputFieldStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/password_icon"
android:hint="#string/password_hint"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:maxLines="1"/>
I'm trying to make the edittext background just a straight line instead of usual. I used custom drawable shape for that. But the line is getting added in the middle of the edittext instead of bottom as the regular edittext line. Also when I press enter, it doesn't remain below the cursor as it should be. Is there any good way to do this?
Custom Drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:color="#FA58AC"
android:width="1dp"/>
</shape>
use this
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape>
<solid android:color="#android:color/white" />
<stroke
android:width="1dp"
android:color="#android:color/holo_green_light" />
</shape>
</item>
</layer-list>
I think It will be helpful for you.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
// Your line color
<solid android:color="#android:color/black" />
</shape>
</item>
<item android:bottom="1dp">
<shape android:shape="rectangle">
// Your background color
<solid android:color="#android:color/white" />
</shape>
</item>
</layer-list>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Name"
android:textSize="10sp"
android:textColor="#color/color_black_light"
android:paddingLeft="10dp"
android:layout_marginTop="10dp" />
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:layout_marginTop="-10dp"
android:padding="10dp"
android:hint="Name"
android:inputType="text"
android:textColor="#color/black"
android:textColorHint="#color/color_black_light"
android:textCursorDrawable="#null" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/edittext_line_color" />