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
Related
I wonder if there is a way to create a view container with an Inner Shadow like in Figma in native Android.
I have already spent the whole day trying layer-list with different items (linear, radial gradients, shapes, bitmaps) but nothing seems to be similar to what I need.
Please check the attachment, pay attention to container's inner shadow, this is what I really need:
Links or parts of code/xml will be appreciated.
Thanks in advance!
Try this:
Example XML for the layer-list:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners android:radius="10dp"/>
</shape>
</item>
<item
android:left="0dp"
android:right="0dp"
android:top="0dp"
android:bottom="10dp">
<shape android:shape="rectangle">
<solid android:color="#00000000"/>
<corners android:radius="10dp"/>
<padding
android:left="0dp"
android:right="0dp"
android:top="0dp"
android:bottom="0dp"/>
</shape>
</item>
</layer-list>
You can set the above XML as the background for the CardView:
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/layer_list_example">
<!-- Add your content here -->
</androidx.cardview.widget.CardView>
Note that you may need to adjust the offset and blur radius to achieve the desired appearance.
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"
This is my TabLayout xml code:
<android.support.design.widget.TabLayout
app:tabBackground="#drawable/profile_tab_selector"
android:id="#+id/profileTabLayout"
android:layout_width="match_parent"
android:layout_height="28dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
app:tabGravity="fill"
app:tabIndicatorHeight="0dp"
app:tabMode="fixed"
app:tabSelectedTextColor="#color/colorPrimary"
app:tabTextColor="#color/white">
</android.support.design.widget.TabLayout>
And this one is for tabBackground="#drawable/profile_tab_selector":
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape>
<stroke android:width="1dp" android:color="#color/white"/>
<solid android:color="#color/white"/>
</shape>
</item>
<item>
<shape>
<stroke android:width="1dp" android:color="#color/white"/>
<solid android:color="#color/blue"/>
</shape>
</item>
</selector>
I want to design it like this, with rounded cornenrs:
The problem is that in selector I can not detect the first and the last tabs to modify them. And this is the result:
You have given the shape in the drawable file , but you didn't give corner radius.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle">
<corners
android:bottomLeftRadius="15dp"
android:bottomRightRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp" />
<stroke
android:width="10dp"
android:color="#android:color/transparent"></stroke>
<solid android:color="#23cf5a" />
</shape>
And you can design something like this too
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:bottomLeftRadius="16dp"
android:bottomRightRadius="16dp"
android:radius="32dp"
android:topLeftRadius="16dp"
android:topRightRadius="16dp" />
<solid android:color="#color/tab_color" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
<size
android:height="32dp" />
</shape>
Your Solution is here
Don't Use : app:tabBackground="#drawable/profile_tab_selector"
Use : android:background="#drawable/profile_tab_selector"
You also try it.
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/
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..