Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make Text View with Rounded Corners in android?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 269
    Comment on it

    In the below example I have created a Text View with Rounded Corners function. Here I have defined style to change background to textview. Below example will clearly describe how to make TextView with Rounded Corners.

    Step(1)-MainActivity-

    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
    }
    

    Step(2)mystyle-

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:state_focused="true" android:state_pressed="true"><shape>
                <stroke android:width="2.3dp" android:color="#a7bf42" />
    
                <corners android:radius="10dp" />
            </shape></item>
        <item android:state_focused="false" android:state_pressed="true"><shape>
                <stroke android:width="2.3dp" android:color="#a7bf42" />
    
                <corners android:radius="10dp" />
            </shape></item>
        <item android:state_focused="true" android:state_pressed="false"><shape>
                <stroke android:width="0.7dp" android:color="#000000" />
    
                <corners android:radius="15dp" />
            </shape></item>
        <item android:state_focused="false" android:state_pressed="false"><shape>
                <gradient android:angle="270" android:centerColor="#F6EBC9" android:endColor="#a7bf42" android:startColor="#a7bf42" />
    
                <stroke android:width="0.7dp" android:color="#000000" />
    
                <corners android:radius="15dp" />
            </shape></item>
        <item android:state_enabled="true"><shape>
                <padding android:bottom="4dp" android:left="4dp" android:right="4dp" android:top="4dp" />
            </shape></item>
    
    </selector>
    

    Step(3)-main_layout-

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginTop="182dp"
            android:text="Evon Developers"
            android:background="@drawable/mystyle"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
    </RelativeLayout>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: