How To Change Font Size In Android Application
Android TextView Ribbon Tutorial
TextViews are the first things that we learn when we set forth learning Android and imputable this whenever we make an Empty Action, then by default we will regard one TextView along the screen with "Hello World!". So, Hello Existence! Hope you are learning healed. In this blog, we will learn TextView decoration in Android. This blog is going to be an interesting blog A we completely use TextViews in our Humanoid application program to display whatsoever textual information. In this blog, we will learn how to beautify these TextViews in Android. Originally, we will learn some of the basic attributes of TextView and after that, we will cost having some cool TextViews in our app. Thus, Lashkar-e-Taiba's get started.
TextView
A TextView is a user interface element that is used to display some text or some matter information in our application. Following is an XML code for using TextView in our application:
<LinearLayout xmlns:humanoid="http://schemas.humanoid.com/apk/res/mechanical man" humanoid:layout_width="match_parent" android:layout_height="match_parent"> <TextView mechanical man:id="@+id/text_view_id" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textual matter="How-do-you-do MindOrks!" /> </LinearLayout> By using the TextView tag in your lotion, you hind end insert a TextView to display the desired text edition by exploitation mechanical man:text property. To decorate a TextView, at that place are various attributes that can be used. Let's discourse one by unity.
Typeface
Away default, Android gives you Little Jo fonts that you can utilisation in your application. They are:
- monospace
- convention
- sans
- serif
You can use these fonts in your TextView by using the android:face attribute.
<TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textual matter="Hello MindOrks! monospace" mechanical man:textSize="24sp" android:typeface="monospace" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="raise" android:layout_marginTop="32dp"/>
Textstyle
You can accentuate a text aside using the android:textStyle attribute. Followers are the three options that are available with android:textStyle :
- bold
- italic
- normal
<TextView android:id="@+id/tv1" mechanical man:layout_width="wrap_content" android:layout_height="wrap_content" humanoid:text="Howdy MindOrks! Bold" android:textSize="24sp" android:textStyle="courageous" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" humanoid:layout_marginTop="32dp"/>
Text sizing and Textbook Color
You can change the text size by exploitation the android:textSize ascribe and the color of the text rear be switch aside using android:textColor attribute.
<TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" mechanical man:textual matter="Hello MindOrks! 32sp" humanoid:textSize="32sp" android:textColor="#11209F" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="32dp"/>
Font family
You lavatory change the font family of a TextView away using the android:fontFamily attribute. Away default, we undergo 14 font families that can make up used in TextView. Approximately of these are serif, monospace, casual, cursive, sans-serif, sans-monospace, etc.
<TextView humanoid:id="@+id/tv1" android:layout_width="wrap_content" humanoid:layout_height="wrap_content" android:text="Hello MindOrks! Cursive script" android:textSize="24sp" android:fontFamily="cursive" android:textColor="#11209F" app:layout_constraintLeft_toLeftOf="bring up" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="nurture" humanoid:layout_marginTop="32dp"/> ImageIf you want to use your custom font and then you can read our blog at MindOrks Blogs.
Textual matter alignment
You can align your text with the help of mechanical man:textAlignment attribute. This assign provides us a great deal of options like center align, textStart, textEnd, viewStart, viewEnd, etc.
<TextView android:id="@+id/tv1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello MindOrks! center adjust" android:textAlignment="center" mechanical man:textSize="24sp" android:textColor="#11209F" app:layout_constraintLeft_toLeftOf="nurture" app:layout_constraintRight_toRightOf="raise" app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="32dp"/>
Text trace
You can put shadow to your text and change the color of the shadow past using the android:shadowColor impute. Also, you tush use shadowDx and shadowDy to specify the offset of the shadow. For example, a -Dx draws a shade off on the left of the text and +Dx draws a vestige connected the right of the schoolbook. shadowRadius can exist old to specify how much the shade should be blurred at the edges.
<TextView android:layout_width="wrap_content" humanoid:layout_height="wrap_content" mechanical man:layout_gravity="center" android:school tex="Hello MindOrks!" humanoid:textSize="50sp" android:padding="12dp" android:shadowColor="#F5A623" android:shadowDx="12" mechanical man:shadowDy="12" android:shadowRadius="8" android:textStyle="bold"/>
Non Breaking Doom
You tush put a sentence in Sir Thomas More than one line. This is possible when the width of the TextView is not decent to hold the table of contents of the TextView i.e. you are having more texts simply the space is non provided.
<TextView android:layout_width="140dp" android:layout_height="wrap_content" android:layout_gravity="kernel" android:text="Hello MindOrks!" android:textSize="50sp" android:textStyle="bold"/>
Gradient
To set the color of the TextView, you can also use up Gradient color by using the LinearGradient.
<TextView android:id="@+id/text" mechanical man:layout_width="wrap_content" humanoid:layout_height="wrap_content" humanoid:gravity="center" humanoid:text="MindOrks" android:textColor="@android:color in/black" humanoid:textSize="60sp" android:textStyle="bold"/> Besides, bring the below code in you MainActivity.karat file to enjoyment LinearGradient:
classify MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val textView = findViewById<TextView>(R.id.text) val shader = LinearGradient(0f, 0f, 0f, textView.textSize, Color.RED, Color.BLUE, Shader.TileMode.CLAMP) textView.paint.shader = shader } } The parameters of the LinearGradient are:
- x0: x-coordinate for start of gradient line. It is of type ice-cream float.
- y0: y-coordinate for set out of slope line. It is of type float.
- x1: x-coordinate for end of slope line. It is of type float.
- y1: y-coordinate for end of gradient line. It is of type float.
- colours: The RGB color to comprise distributed along the slope line. It is of type float.
- positions: IT is the relative position of each corresponding color the colors array. Information technology is of type float.
- tile: It is the shader tiling musical mode. It is of eccentric float.
Clickable span
Spell reading a text edition, you can go to somewhere else by clicking on the schoolbook. This is the selfsame way as used in websites, where we use hyperlinks to open new page from the alive one. Add the below code in your XML file:
<TextView xmlns:android="hypertext transfer protocol://schemas.humanoid.com/apk/reticuloendothelial system/android" android:Idaho="@+ID/text" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="16dp" android:paddingLeft="16dp" humanoid:paddingRight="16dp" android:paddingTop="16dp" android:textSize="24sp" android:text="Patc reading to the text, you can attend settings in the midst." humanoid:textColorLink="#444" android:textColorHighlight="#11209F"/> Hither, textColorLink is the color of the clickable link and the textColorHighlight is the color used when you click the link.Add the below code in your MainActivity.kt file away:
separate MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val textView = findViewById<TextView>(R.Gem State.text) val text = textView.text.toString() val goToSettings = getString(R.string.go_to_settings) val start = textual matter.indexOf(goToSettings) val end = start + goToSettings.length val spannableString = SpannableString(text) spannableString.setSpan(GoToSettingsSpan(), take up, end, 0) textView.text = spannableString textView.movementMethod = LinkMovementMethod() } private class GoToSettingsSpan: ClickableSpan() { overturn fun onClick(sentiment: Panoram) { view.context.startActivity(Intent(Settings.ACTION_SETTINGS)) } } }
Background Image
You can use some background image in TextView i.e. information technology seems care the text is written on the image. Add the down the stairs code in your XML file:
<TextView xmlns:mechanical man="http://schemas.android.com/apk/RES/android" mechanical man:id="@+id/text" android:layout_width="wrap_content" mechanical man:layout_height="wrap_content" android:layout_gravity="center" humanoid:graveness="center" mechanical man:text="MindOrks!" android:textColor="#000000" android:textSize="80sp" android:textStyle="bold"/> After that, add the below code in your MainActivity.carat file:
social class MainActivity : AppCompatActivity() { reverse fun onCreate(savedInstanceState: Bundle?) { A-one.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val textView = findViewById<TextView>(R.I.D..text) val bitmap = BitmapFactory.decodeResource(resources, R.drawable.bg) val shader = BitmapShader(electronic image, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT) textView.paint.shader = shader } }
Conclusion
In this blog, we learned how we can decorate TextViews in our application. We learned many ways of decorating the text used in our application. Go for you enjoyed this blog and will implement the learnings of this blog in your application.
Keep Learning :)
Squad MindOrks!
How To Change Font Size In Android Application
Source: https://blog.mindorks.com/android-textview-decoration-tutorial
Posted by: harrisoncontaked.blogspot.com

0 Response to "How To Change Font Size In Android Application"
Post a Comment