• Latest Code...

    Featured Post

    Implementing Hilt in a Kotlin Android Jetpack Compose Project with MVVM Architecture

     In modern Android development, maintaining a scalable codebase can be challenging, especially when it comes to dependency management. Hilt,...

    Oreo: Auto-sizing Textview in Android Studio using Kotlin


    Android 8.0 (API level 26) allows you to instruct a TextView to let the text size expand or contract automatically to fill its layout based on the TextView's characteristics and boundaries. This setting makes it easier to optimize the text size on different screens with dynamic content.

    First important part to enable auto sizing textview, put this in textview:
    
    
    android:autoSizeTextType="uniform"

    This can explore the vertically and horizontally, ignoring text size.

    If you are using support library make sure you have to use:
    
    
    xmlns:app="http://schemas.android.com/apk/res-auto"
    
    
    You can not use wrap content both layout height and width, because that may produce unexpected result, instead match parent or fix size. 

    You can use either framework or support library to set up the autosizing of TextView programmatically or in XML. To set the XML attributes, you can also use the Properties window in Android Studio.
    There are three ways you can set up the autosizing of TextView:


    Note: If you set autosizing in an XML file, it is not recommended to use the value "wrap_content" for the layout_width or layout_height attributes of a TextView. It may produce unexpected results.

    Now, if you are using from xml, the do following :



    If you want make from programmatically then do this:


    Here are array inside the values/arrays.xml, please make sure name should be same as in textview properties.



    Here is the simple output that looking like:
    Clone/Download/Fork/Star Full Source Code From github

    Source:  Developer.android.com
    #ILoveKotlin #PrAndroid #KotlinTutorials #AndroidTutorials

    Contact Form

    Name

    Email *

    Message *