Home » Android » android – Two text in button, title and subtitle

android – Two text in button, title and subtitle

Posted by: admin June 15, 2020 Leave a comment

Questions:

Can we create some custom button with title and subtitle text in it.

Title in upper part of button and subtitle below it.

How to&Answers:

Here is the answer 🙂

You do not need any images the thing you need is styled text
and here is simple and short way to do it

button1.setText(Html.fromHtml("<b><big>" + "Title" + "</big></b>" +  "<br />" + 
        "<small>" + "subtitle" + "</small>" + "<br />"));

You do not need to change any layout just add this text to your button

Answer:

you can solve this problem logically the logic is that.

android:text="Titel \n subTitle"

I hope it is help full to you.

Answer:

In XML you could use a relative layout and make the other text be on top of the button.

This is just an example, haven’t tired the code.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">


<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="25dp"
    android:id="@+id/button"
    android:text="Text1" />
<TextView
    android:id="@+id/label"
    android:layout_alignBottom="@id/button"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Text2"/>
</RelativeLayout>