What I want to do is have something like the picture below.
The whole rounded corner rectangle needs to be clickable. Then Record: ### and ### need to be some sort of TextView or String. The green check mark needs to be an ImageView.
I am having trouble even knowing where to start with this. I know there is a way to achieve this because the app Unblock Me has something sort of like how I want it. Below is a screenshot of their app.
Any help on ideas of how to achieve this?
It is kind of easy.
First that rounded rectangle can be a linear layout ok.
In its background attribute you pass a layer list which will contain two items having colors black and white with radius of lets say 5dp
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- "background shadow" -->
<item>
<shape android:shape="rectangle" >
<solid android:color="#DDDDDD" />
<corners android:radius="15dp" />
</shape>
</item>
<!-- background color -->
<item
android:bottom="5px"
android:left="5px"
android:right="5px"
android:top="5px">
<shape android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<corners android:radius="8dp" />
</shape>
</item>
</layer-list>
put this in a xml file and save it in a drawable folder and put it in the background attribute of your linear layout.
Now in your layout, with orientation horizontal, put three child elements
two textviews and one imageview with weights 35, 35, 30 and set image to the imageview that green tick mark sign.
Voila!
Related
How can I change the color of the card view elevation?
Or make it softer
It gets dark when I increase the app:cardElevation value
Add these 2 properties to your CardView
android:outlineAmbientShadowColor="#color/yourShadowColor"
android:outlineSpotShadowColor="#color/yourShadowColor"
here you can change color first you can make a drawable file and paste this code in it. then in your layout inside cardview, you can assign as background file.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<corners android:bottomLeftRadius="8dp"
android:topLeftRadius="5dp"
android:bottomRightRadius="8dp"
android:topRightRadius="5dp"/>
<solid android:color="#ddd"/>
</shape>
</item>
I'm a beginner on Android Studio and I need your help to apply a specific transparency on my layout.
I applied a background and border color to my layout by using this drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#android:color/black" />
<corners android:radius="3dp" />
<stroke android:width="5px" android:color="#ffa500" />
</shape>
Now I want to apply dynamically a transparency to this button (by using a seek bar) but only on the background color I don't want to modify my border color.
I tried to use setAlpha function but it also change my border color transparency.
How can I do this?
Thanks.
In your shape change the <solid android:color="#android:color/black" /> to <solid android:color="#00FFFFFF" />
This will make your shape transparent.
And in your xml <Button .... android:background="#drawable/your_shape" />
You need to use the alpha portion of the color your specify in item.
For example - #aarrggbb -- aa part is the alpha.
If you want to change stroke / solid color separately, I recommend using GradientDrawable to setStroke() and `setColor()'.
For reference -
https://developer.android.com/reference/android/graphics/drawable/GradientDrawable#setColor(int)
https://developer.android.com/reference/android/graphics/drawable/GradientDrawable.html#setStroke(int,%20android.content.res.ColorStateList,%20float,%20float)
Is it possible to draw a line like shown in the fig. using android xml ? I need it for setting a background for view pager indicator
If you need hard edges like that, I'd suggest using a 9-patch: http://developer.android.com/tools/help/draw9patch.html
If you're ok with soft edges, you can use a gradient (which I got from using this online tool):
<gradient
android:angle="0"
android:centerX="50%"
android:centerColor="#000000"
android:startColor="#FF0000"
android:endColor="#FF0000"
android:type="linear"
/>
create a new drawable like this
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="-100dp"
android:top="-100dp">
<shape android:shape="rectangle">
<stroke
android:width="100dp"
android:color="#FF0000" />
<solid android:color="#ffffff" />
</shape>
</item>
</layer-list>
and then add this as background.
I have ImageButton on the layout of my application and I want to have rounded corners for this ImageButton, so I'm using style like:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1dp"
android:color="#android:color/black" />
<corners android:radius="15dp" />
<solid android:color="#android:color/black"/>
</shape>
and then I'm using android:background="#drawable/my_rounded_shape.xml"/>
The problem is that after this I want to change background color from black to some custom color, but I can't modify style programmatically and there is no way to generate new style with corners but with different color and apply to my ImageButton.
Could you clarify is there any way to do it or any workaround?
Try it:
Create another XML Shape With Name For Example "SS"
and with your new properties
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp"
android:color="#android:color/red" />
<corners android:radius="10dp" />
<solid android:color="#android:color/blue"/>
After then
Button b = (Button) (findViewById(R.id.button1));
b.setBackgroundDrawable(getResources().getDrawable(R.drawable.ss));
After some time I came up with solution for my case - in my Java code I do something like:
GradientDrawable drawable = (GradientDrawable) imageButton.getBackground();
drawable.setColor(color);
This allows me to save rounded corners described in my "shape" and change background color at the same time.
I've defined a custom shape in my res/drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:color="#FF404040"
android:width="1dp"
android:dashGap="3dp"
android:dashWidth="3dp"
/>
<size
android:height="1dp"
/>
</shape>
I'm using it as a background for one of my views. The shape is positioned vertically centered inside the view, but I want it to appear at the bottom of the view instead, is there a way to do this?
I am not sure there is a way to do position shape inside a view. However as a workaround I would consider something like this.
<RelativeLayout >
<OldView with shape as background now without any background
android:layout_alignParentTop="true" android:layout_alignParentBottom="true"/>
<View with this shape as background
android:layout_alignParentBottom="true"/>
</RelativeLayout>
This will supposedly give you what you want to achieve.
Try this , this may be useful,
http://thinkandroid.wordpress.com/2010/01/14/how-to-position-views-properly-in-layouts/
Set your custom view as background of layout or view.
or if not useful then provide your layout xml file code here so i can help you more easily.
The following receives the margin layout params of the shape so that you can change the views' margins, positioning it anyway you want:
MarginLayoutParams params = (MarginLayoutParams)shape.getLayoutParams();
// Sets the margins of the shape, making it move to a specific location on the screen
params.setMargins(int left, int top, int right, int bottom);
I had a similar problem, but I wanted to have a background for my views, a rectangle, but only left and bottom sides of the rectangle to be shown, and no top or right ones. In order to achieve this, I have used this xml:
<?xml version="1.0" encoding="utf-8"?>
<item
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp">
<shape
android:shape="rectangle" >
<stroke
android:width="1px"
android:color="#FFFF00" />
</shape>
</item>
<item
android:bottom="3dp"
android:left="3dp"
android:right="1dp"
android:top="1dp">
<shape
android:shape="rectangle" >
<stroke
android:width="1px"
android:color="#000000" />
</shape>
</item>
Note: There are two rectangles, one drawn on top of the other, the second one drawn on top of the first, but a bit shifted, so that 1dp of the first one to be shown on screen on the left and bottom. Also, you must note that the color of the second one must be chosen to be the one who hides. In my case it was the black color.
The result is (You may observe yellow lines only on the left and bottom):
I know gravity works on other kinds of drawables
android:gravity=["top" | "bottom" | "left" | "right" | "center_vertical" |
"fill_vertical" | "center_horizontal" | "fill_horizontal" |
"center" | "fill" | "clip_vertical" | "clip_horizontal"]
Here is my decision to embed blocks
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid android:color="#f00" />
<corners android:radius="50dp" />
<padding android:bottom="20dp" />
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid android:color="#090" />
<corners android:radius="50dp" />
<padding
android:top="450dp"
/>strong text
</shape>
</item>
</layer-list>