Rounded Corners and Borders in Android Studio

I want to add rounded corners and borders to a textview. But only the top corners should be rounded and the bottom should be without border. Already found this:

https://www.android-examples.com/add-rounded-border-to-textview-programmatically/

But then I have rounded corners at the bottom too.

How can I change this?

Create a drawable file like this :

    <?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:insetBottom="-4dp">

    <shape android:shape="rectangle">
        <solid android:color="#FFFFFF" />
        <stroke android:width="4dp" android:color="#000000" />
        <corners android:radius="4dp" />
    </shape>

</inset>

And then apply it as an background of any control and there you go, it's done.

How to make layout with rounded corners..?, This in-built feature makes rounded corners very easy to implement. instead of android:background (since background is used for the rounded shape). a drawable with a white background, black border and rounded corners: It allows customizing the rounded corners, stroke color and width, and elevation. Example: If you want to add rounded corner to any kind of android view like linear layout, relative layout, button etc., follow the below method Method 1 Create a xml file under your drawable folder with following code. (The name of the file I created is rounded_corner.xml)

With the Material Components Library you can use the MaterialShapeDrawable to draw custom shapes.

With a TextView you can do:

<TextView
    android:id="@+id/tv_rounded"
    android:paddingLeft="8dp"
    ../>

Then create a MaterialShapeDrawable. Something like:

    TextView textview = findViewById(R.id.tv_rounded);
    ShapeAppearanceModel shapeAppearanceModel = new ShapeAppearanceModel()
        .toBuilder()
        .setAllCorners(CornerFamily.ROUNDED,radius)
        .setBottomRightCorner(CornerFamily.ROUNDED,0)
        .setBottomLeftCorner(CornerFamily.ROUNDED,0)
        .build();
    MaterialShapeDrawable shapeDrawable = new MaterialShapeDrawable(shapeAppearanceModel);
    shapeDrawable.setStroke(2.0f, ContextCompat.getColor(this,R.color.xxxx));
shapeDrawable.setFillColor(ContextCompat.getColorStateList(this,R.color.xxx));    
    ViewCompat.setBackground(textview,shapeDrawable);

How to create a layout with rounded corner borders in Android , In Android, when you define your user interface in XML, you can define a border for layouts Duration: 9:19 Posted: Nov 24, 2015 Rounded Corners. In this quick article we will see how to add Rounded corners to Views and Layouts. This can be done on Layout XML or Programatically. Here we will see both the ways. Rounded Border with Transparent Inside. Create an xml inside Drawable Folder with below code. Name it rounded_red_border.xml

Create Draweable rounded_border.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <padding
        android:bottom="3dp"
        android:left="3dp"
        android:right="3dp"
        android:top="3dp" />

    <stroke
        android:width="1dp"
        android:color="#FFFFFF" />

    <corners
        android:radius="5dp" />

    <size
        android:width="110dp"
        android:height="110dp" />
</shape>

Then Set this Drawable in view's background property

 <TextView
    android:id="@+id/tv_register"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tv_are_you_new_user"
    android:layout_margin="5dp"
    android:background="@drawable/rounded_border"
    android:fontFamily="@font/montserrat"
    android:gravity="center_horizontal"
    android:padding="10dp"
    android:text="Register"
    android:textAllCaps="true"
    android:textColor="@color/blue"
    android:textSize="15sp" />

Also helpful this solution to you: Click Me

Hope this may help you

Add Rounded Corners to Views and Layouts Android, Rounded Border with Transparent Inside. Rounded Corners. Create an xml inside Drawable Folder with below code. Name it� If you're just looking to create a shape that rounds the corners, removing the padding and the stroke will do. If you remove the solid as well you will, in effect, have created rounded corners on a transparent background. For the sake of being lazy I have created a shape underneath, which is just a solid white background with rounded corners - enjoy!

Rounded Corner in Android Studio || material design, Enjoy the videos and music you love, upload original content, and share it all with friends, family Duration: 6:56 Posted: Feb 13, 2018 In this tutorial we will see how to make a Button with rounded corners. In some applications we can see the button with rounded corners and borders.Android is not providing any default Button widget with rounded corners , but we can achieve this by setting a drawable background for the default Button in android.

Android TextView With Rounded Corner and Border, It needs to ripple, have rounded corners… oh, and three borders… <ripple xmlns:android="http://schemas.android.com/apk/res/android" Add rounded corners border to TextView using xml Android.Creating textView with rounded border using external layout xml file.corners android:radius="20dp".

Creating a Ripple Drawable with Bordered, Rounded Edges, In this Android tutorial, we'll create rounded corners with a stroke -- or border. The finished Built with Android Studio and Kotlin. updated 11� To make the border, you need the stroke tag. You can select a color and width of the border with the stroke tag. To use it use the border drawable for the background attribute. Dashed border for a button that changes on click

Comments
  • add your code segment for more understand of your question
  • Checkout this solution : stackoverflow.com/a/50148012/3974530
  • The corners are perfect, thanks! But how can I add the border?
  • But then the border is at the tottom too
  • What do you want to achieve? Please upload photo of that
  • I want the border to be at the left, right and top. The bottom should be borderless
  • The borders are correct now. Combined with <corners android:topLeftRadius="5dp" android:topRightRadius="5dp"/> it's perfect!