androidandroid-stylesandroid-singleline

How to effectively replace singleLine with maxLines in style?


I have a style as below

<style name="PennyTextSingleLine">
    <item name="android:textSize">@dimen/text_size_penny</item>
    <item name="android:textColor">@color/color_default</item>
    <item name="android:singleLine">true</item>
</style>

And later I have another style that is all the same except not single line. So I write

<style name="PennyTextMultiLine" parent="PennyTextSingleLine">
    <item name="android:singleLine">false</item>
</style>

That's very useful.

However, as we know singleLine is deprecated as per Alternative of singleLine attribute (Deprecated) TextInputEditText. It is suppose to be replaced by

<item name="android:maxLines">1</item>

How could I tackle the above (e.g. any way to represent the below with maxLines)?

<item name="android:singleLine">false</item>

Solution

  • I know I can do the below

    <style name="PennyTextSingleLine" parent="PennyTextMultiLine">
        <item name="android:maxLines">1</item>
    </style>
    
    <style name="PennyTextMultiLine" >
        <item name="android:textSize">@dimen/text_size_penny</item>
        <item name="android:textColor">@color/color_default</item>
    </style>
    

    But, that would involve too many search around of my existing codes to swap the hierarchical relationship. I wonder if there's a 1-1 where we could override the maxlines=1 to any number at the parent hierarchy.

    Post my answer here, but hope for a better answer out there.