How to achieve this in android? Any better waysFading shade border for imageview,imagebutton
You can create your own drawable to achieve this.
The code for your Border.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="#android:color/darker_gray" />
<corners android:radius="5dp"/>
</shape>
</item>
<item android:right="1dp" android:left="1dp" android:bottom="2dp">
<shape
android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>
Implement this in your layout by using android:background="#drawable/border".
Android also has some options.
android:background="#android:drawable/dialog_frame"
You could also use websites like http://inloop.github.io/shadow4android/ to achieve it. Here is tutorial for 9Patch: http://radleymarx.com/blog/simple-guide-to-9-patch/
Related
I want to create edittext and button like this. I am not able to create the bottom shadow and round corner. please help me to design the xml.
This is my xml code
<item>
<shape android:shape="rectangle">
<solid android:color="#2CB386" />
<corners android:radius="5dp"/>
</shape>
</item>
<item android:bottom="5px">
<shape android:shape="rectangle">
<solid android:color="#F5F2F2" />
</shape>
</item>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Deep Green shadow. -->
<item android:left="3dp" android:top="5dp">
<shape>
<solid android:color="#046A4B" />
<corners android:radius="15dp" />
</shape>
</item>
<!-- Green foreground. -->
<item android:bottom="5dp" android:right="3dp">
<shape>
<solid android:color="#2CB386" />
<corners android:radius="15dp" />
</shape>
</item>
Create a button_bg.xml file under drawable folder and set your button background to button_bg.xml
android:background="#drawable/button_bg"
New to programming, 3 weeks beginner.
I am making a button with stacked rectangles through drawable xml.
This is my button .xml code, very straight forward:
<?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:background="#D5A04F"
tools:context=".MainActivity">
<android.support.design.widget.NavigationView
<Button
android:id="#+id/leftnavbar"
android:layout_width="212dp"
android:layout_height="279dp"
android:layout_marginTop="16sp"
android:layout_marginBottom="500sp"
android:background="#drawable/rounded_rectangle"
/>
</android.support.design.widget.NavigationView>
</android.support.constraint.ConstraintLayout>
and this is my drawable .xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingBottom="#dimen/mr_dialog_fixed_width_minor"
android:paddingTop="#dimen/mr_dialog_fixed_width_major"
>
<item
android:top="5sp"
android:left="5sp"
android:right="5sp"
android:bottom="50sp">
<shape android:shape="rectangle">
<solid android:color="#D3AE71" />
<corners android:radius="20sp"/>
</shape>
</item>
<item
android:top="30sp"
android:left="30sp"
android:right="30sp"
android:bottom="600sp">s
<shape android:shape="rectangle">
<solid android:color="#E6E5E5" />
<corners android:radius="20sp"/>
</shape>
</item>
<item
android:top="160sp"
android:left="30sp"
android:right="30sp"
android:bottom="470sp">
<shape android:shape="rectangle">
<solid android:color="#E6E5E5" />
<corners android:radius="20sp"/>
</shape>
</item>
<item
android:top="290sp"
android:left="30sp"
android:right="30sp"
android:bottom="340sp">
<shape android:shape="rectangle">
<solid android:color="#E6E5E5" />
<corners android:radius="20sp"/>
</shape>
</item>
<item
android:top="420sp"
android:left="30sp"
android:right="30sp"
android:bottom="210sp"
>
<shape android:shape="rectangle">
<solid android:color="#E6E5E5" />
<corners android:radius="20sp"/>
</shape>
</item>
<item
android:top="550sp"
android:left="30sp"
android:right="30sp"
android:bottom="80sp">
<shape android:shape="rectangle">
<solid android:color="#E6E5E5" />
<corners android:radius="20sp"/>
</shape>
</item>
</layer-list>
The only item that is shown in drawable is the first, the rest of the rectangles fail to show.
Suggestions or pointers to the reason will be much apreciated. thank you for your time and attention...
First of all please do not use "sp" for things other than text font size.
Second, pls look into excessive size of your android:bottom, like 600sp for example - they are leaving no space for respective shapes.
Your button's height is too short,chang android:layout_height="279dp" to android:layout_height="700dp"
I want to make this shape,for that i tried layer-list to design such shape but it doesn't happen exactly what i want.
<?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="#color/APP_PRIMARY"/>
<corners android:topRightRadius="100dp"
android:bottomRightRadius="100dp"/>
</shape>
</item>
<item android:width="100dp" >
<shape android:shape="rectangle">
<solid android:color="#color/white"/>
<corners android:topRightRadius="90dp"
android:bottomRightRadius="90dp"/>
</shape>
</item>
</layer-list>
Output of above code is
Desired Output.
This is what you exactly want
<?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="#color/colorPrimary"/>
<corners android:radius="90dp"
/>
</shape>
</item>
<item android:width="100dp" >
<shape android:shape="rectangle">
<solid android:color="#ffff"/>
<corners android:radius="90dp"/>
</shape>
</item>
<item android:width="90dp" >
<shape android:shape="rectangle">
<solid android:color="#color/red"/>
<corners android:radius="90dp"
/>
</shape>
</item>
Inform me either it works or not. Thanks
you can use horizontal linear layout consists of two views
the right view you can use this drawable
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The bottom layer is blue square.-->
<item
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp">
<shape>
<solid android:color="#color/accentYellowCanary" />
<size android:height="100dp"
android:width="200dp" />
<corners android:topLeftRadius="50dp"
android:bottomLeftRadius="50dp"
android:topRightRadius="50dp"
android:bottomRightRadius="50dp"/>
</shape>
</item>
<!-- The middle layer is green circle.-->
<item
android:left="5dp"
android:top="5dp"
android:right="150dp"
android:bottom="5dp">
<shape android:shape="oval">
<size
android:width="100dp"
android:height="100dp" />
<solid android:color="#FFF" />
</shape>
</item>
which will result :
and for the left one you can use
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The bottom layer is blue square.-->
<item
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp">
<shape>
<solid android:color= "#color/offWhite"/>
<size android:height="100dp"
android:width="200dp" />
<corners android:topLeftRadius="50dp"
android:bottomLeftRadius="50dp"
android:topRightRadius="50dp"
android:bottomRightRadius="50dp"/>
</shape>
</item>
Is it possible to to have multiple shapes in a single drawable?
I am trying to create "progressDrawable" for seekbar; by making individual circles and offsetting with padding(Not a good idea I guess) in a single drawable resource file.
But doesn't seem to work as it shows in "preview" in Android Studio.
I have just started Android development; please help me figure this out guys. Also I feel there might be a better way to get this done, instead of making these individual circles in drawable file.
I'm trying to create something like this:
What I have accomplished so far:
<SeekBar
android:id="#+id/slider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/seekbar_cancel"
android:layout_toLeftOf="#+id/seekbar_apply"
android:progressDrawable="#drawable/custom_seeker"
/>
custom_seeker.xml:
<?xml version="1.0" encoding="utf-8"?>
<item android:top="0dp" android:left="0dp" android:bottom="7dp" android:right="7dp">
<shape android:shape="oval">
<size android:width="1dp"
android:height="1dp"/>
<solid android:color="#f06"/>
</shape>
</item>
<item android:top="0dp" android:left="2dp" android:bottom="7dp" android:right="5dp">
<shape android:shape="oval">
<size android:width="1dp"
android:height="1dp"/>
<solid android:color="#0f0"/>
</shape>
</item>
<item android:top="0dp" android:left="4dp" android:bottom="7dp" android:right="3dp">
<shape android:shape="oval">
<size android:width="1dp"
android:height="1dp"/>
<solid android:color="#0f8"/>
</shape>
</item>
<item android:top="0dp" android:left="6dp" android:bottom="7dp" android:right="1dp">
<shape android:shape="oval">
<size android:width="1dp"
android:height="1dp"/>
<solid android:color="#f00"/>
</shape>
</item>
Is it possible to to have multiple shapes in a single drawable?
Yes, you should use layer-list
Every time I try to customize the style of a view I have the same problem.
What parameters can I change; and how to override the system defaults? For example:
How to change the highlighted color of a element of a ListView when clicked
How to change the default frame of a DialogFragment? I mean the frame that is removed with the Style DialogFragment.STYLE_NO_FRAME.
Where can I check what are the values I should play with for achieve my custom layouts?
Thanks
Well you can change the look by creating a new xml file in the drawable folder but dont make a layout xml jus pick andrid xml from the wizard and it will give u a list of components you can modify including colour.
<?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="#android:color/black" />
</shape>
</item>
<item android:top="1dp" android:left="2dp" android:right="2dp" android:bottom="25dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/holo_purple" />
</shape>
</item>
<item android:top="1dp" android:left="400dp" android:right="2dp" android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/holo_purple" />
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp" android:topLeftRadius="7dp"
android:topRightRadius="7dp" />
</shape>
</item>
<item android:top="1dp" android:left="2dp" android:right="400dp" android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/holo_purple" />
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp" android:topLeftRadius="7dp"
android:topRightRadius="7dp" />
</shape>
</item>
</layer-list>
then you can just change whats required!
But provider some code and i will be able to answer better..