I'm trying to achieve this:
I know that using a vertical LinearLayout that constains a TextView and just below a View that works as a line is a possible a solution, but I'd not like to use 3 widgets to achieve that. What I want is to use only a TextView and draw the line using a drawable. I have done an implementation but it does not work (I do not see the line). Find below the code I wrote:
<TextView
android:layout_width="100dp"
android:layout_height="150dp"
android:gravity="center"
android:text="Text"
android:drawableBottom="#drawable/line"/>
line.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="10dp" android:color="#3b50ec"/>
</shape>
If is possible to achieve what I want using my approach, does anyone know what's wrong in my code?
The problem is in your line.xml file, replace its content for this implementation:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<size
android:height="1dp"
android:width="100dp" />
<solid android:color="#3b50ec" />
</shape>
I think to do this requires a 9 patch. Here's one from the sdk (ab_transparent_dark_holo.9.png):
And then change it to a background attribute:
<TextView
android:layout_width="100dp"
android:layout_height="150dp"
android:gravity="center"
android:text="Text"
android:background="#drawable/line"/>
Related
I want to design an sign in interface for my sample app, and like other app in the sign in i have 3 button.
Sign in by using google
Sign in by my app's account
Sign up an account
each button i had corner it through xml, but i still want some gradient in it but dont know how to add up
i did try add gradient into xml file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:bottomRightRadius="45dp"
android:bottomLeftRadius="45dp"
android:topRightRadius="45dp"
android:topLeftRadius="45dp"
></corners>
<gradient
android:startColor="#color/white"
android:endColor="#AEAEAE"
android:angle="120"></gradient>
</shape>
but the button always come out at it's base color and the corner still round
I'm still a newbie so I'd appreciate it if anyone could give step-by-step answers. Thanks
Try using AppCompatButton instead of Button.
<androidx.appcompat.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_background"/>
You can use AppCompatTextView, with android:background="#drawable/button_background" and don't forget make it clickable android:clickable="true" android:focusable="true"
Example
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:clickable="true"
android:focusable="true"
android:background="#drawable/button_background"
android:text="sign_in" />
If you want ripple effect you can add it in button_background like this
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#8014B3">
<item>
<shape android:shape="rectangle">
<corners
android:bottomRightRadius="45dp"
android:bottomLeftRadius="45dp"
android:topRightRadius="45dp"
android:topLeftRadius="45dp"
></corners>
<gradient
android:startColor="#color/white"
android:endColor="#AEAEAE"
android:angle="120"></gradient>
</shape>
</item>
</ripple>
Help me please.
How can i do fab like this.
What i must use, that i can do this.
Maybe you know, that i can read about my problem?
Are there any samples / examples to perform such a transformation?
I tried using a background, but it's doesn't work
Problem in making this view.
FloatingActionButton hides all view on it. So your dot view can not be placed upon FAB. So we have to make ImageView instead of FAB.
Put this in your layout.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/blue_circle"
android:padding="15dp"
android:src="#mipmap/ic_launcher" />
<ImageView
android:layout_width="13dp"
android:layout_height="13dp"
android:layout_gravity="top|right"
android:src="#drawable/red_circle" />
</FrameLayout>
make new xml in res>drawable>blue_circle_gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient
android:endColor="#8e81fc"
android:startColor="#7264EA" />
</shape>
make new xml in res>drawable>red_circle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#ff0000" />
</shape>
Output will be same like this:
I am trying not to use image view. This is because, later, I will generate many objects with the same shape but different colors, so I wouldn't need to keep adding image views but simply adding colors on my code.
How can I create those images on Android Studio? I looked over Paint, onDraw, Canvas, etc, but this looks difficult to me.
If you want to use from XML , Try this way it will work
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<size
android:width="100dp"
android:height="40dp" />
<solid android:color="#5EB888" />
<corners android:radius="0dp"/>
</shape>
</item>
<item
android:top="-26dp"
android:bottom="31dp"
android:left="-90dp"
android:right="75dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
</layer-list>
OUTPUT
You can create vector image using any vector program like Adobe Illustrator or convert it using a conversion tool like vectormagic or find already existing one then import it to android studio.
it will be imported as xml file where you can change the colors as you want
Create a drawable file as named left_arrow.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<rotate
android:fromDegrees="45"
android:toDegrees="90"
android:pivotX="0%"
android:pivotY="1%" >
<shape android:shape="rectangle" >
<stroke
android:width="10dp"
android:color="#00000000" />
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
Now, create a view layout to create this type of stripes or image like this, here is the below code:-
<?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">
<LinearLayout
android:id="#+id/llMain"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:background="#color/black"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1"
android:background="#drawable/left_arrow"
android:contentDescription="#string/app_name" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:contentDescription="#string/app_name" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9" />
This above layout creates the required arrow stripe as a layout.
Now add this layout to your required layout where you wan't to show this stripes. For example,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/llMain"
layout="#layout/xtra"/>
</LinearLayout>
Now, you are able to also use OnClickListener by using "llMain".
Hope it will help.
You could use the white png image you already have and use the setColorFilter method on the image view class to tint it with any color you desire
I am trying to create a circular layout that always stay's on the screen.
To do so, I have created a System overlay and added a button.
But, now I want to make it round.
Either I can use 4 different ImageView and and textView and add both to FrameLayout.
I read somewhere that simple things like this can be made by XML.
How do I do it?
I want to achieve something like this :
EDIT
After following your guide I was able to achieve this :
But I am not satisfied by the way I used.
What I did was created 2 shaped (background, forground) and added them to a layerlist.
BACKGROUND
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid android:color="#50000000" />
</shape>
FORGROUND
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid android:color="#99009900" />
</shape>
LIST
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/circleback">
</item>
<item
android:bottom="5dp"
android:drawable="#drawable/circlefront"
android:left="5dp"
android:right="5dp"
android:top="5dp">
</item>
</layer-list>
Then, I used a framelayout and added 2 textview.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/circle" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="33dp"
android:text="#string/data_left"
android:layout_marginTop="8dp"
android:textColor="#fff"
android:textSize="30sp"
android:typeface="sans"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:text="#string/band"
android:layout_marginTop="40dp"
android:textColor="#fff"
android:textSize="20sp"/>
</FrameLayout>
And then inflated them by service. But I am not happy with the textposition and the fact that I have to random hit and trial to find center of circle.
I'll later add pinch to zoom to view so, I really want to find a way that text align itself to centre of circle.
You need to create a shape drawable (in the res/drawable folder) like:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"
<solid android:color="#ff00ff00 />
</shape>
See docs: https://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
I want to create custom button with rounded bottom right and top right corners.
However, I get bottom left and top right rounded instead, although my implementation seems to be ok.
What am I doing wrong?
I use following shape definition stored in drawable folder:
button_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#F66622"/>
<padding
android:left="5dip"
android:top="5dip"
android:right="5dip"
android:bottom="5dip"
/>
<corners
android:radius="20dip"
android:bottomLeftRadius="0dip"
android:topLeftRadius="0dip"
/>
</shape>
and the layout file is this:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg"
>
<Button
android:id="#+id/btnFoo"
android:text="#string/btn_foo_title"
android:background="#drawable/button_shape"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:layout_centerInParent="true"
android:textSize="26sp"
/>
</RelativeLayout>
This is the result:
I also tried to define each corner radius separately in the button_shape file
...
<corners
android:bottomLeftRadius="0dip"
android:topLeftRadius="0dip"
android:bottomRightRadius="20dip"
android:topRightRadius="20dip"
/>
...
... with the same result.
Is it possible that this functionality is somehow messed up in Android SDK?
Silly question, but did you try rounding bottomLeft and see if it rounds the bottom-right corner? I know it's not a true solution, but work-arounds are nice too. If it looks the way you want, it doesn't matter how you achieve it.