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..
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"
I am a newbie in Java-Android developing.
I want to add this drawable on a view like button's background
but it doesn't draw anything.
This is my background drawable_shining.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<gradient
android:endColor="#000"
android:centerColor="#111"
android:startColor="#000"
android:angle="45"
android:type="linear" />
</shape>
</item>
<item>
<shape>
<gradient
android:endColor="#000"
android:gradientRadius="100"
android:startColor="#555"
android:type="radial" />
</shape>
</item>
</layer-list>
[here is code and layout][1]
according to documentation layer-list is a drawable object that manages an array of other drawables. Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top.
Each drawable is represented by an element inside a single element.
in your code, write each <shape> in <item> tag. Your final code will be look like this,
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<gradient
android:endColor="#000"
android:gradientRadius="100"
android:startColor="#333"
android:type="radial" />
</shape>
</item>
<item>
<shape>
<gradient
android:endColor="#000"
android:gradientRadius="100"
android:startColor="#333"
android:type="radial" />
</shape>
</item>
You can use same format like below code :
Reference : angrytools
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="14dp"
/>
<gradient
android:angle="45"
android:centerX="35%"
android:centerColor="#47A891"
android:startColor="#E8E8E8"
android:endColor="#000000"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#878787"
/>
</shape>
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
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/
I need to make a custom rectangle that should use hex colors from #bff54a up to #88c010.
Actually I have this xml but I can only use one of those colors. How can I make the gradient possible? I already searched and I didn't found anything like this.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="#color/gray_light" />
<solid android:color="#88c010" />
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
</shape>
Thanks to all!
Use Gradient as the color of the Drawable :
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="#color/gray_light" />
<gradient
android:type="linear"
android:centerX="0"
android:centerY="1"
android:startColor="#bff54a"
android:endColor="#88c010" />
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
</shape>
See Drawable Resources
You can create file shape and implement this code
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangule"> <!-- oval -->
<gradient
android:startColor="#388E3C"
android:endColor="#448AFF"
android:centerColor="#color/colorPrimary"
/>
</shape>
</item>
</selector>
Result