How to use two different font sizes for button text in Android?

本秂侑毒 提交于 2019-12-05 19:33:52

Hopefully this will help. This off course is not the only solution but it is a pretty simple one. Add the xml part in your xml instead of the button.

XML

<LinearLayout
    android:id="@+id/button_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp" 
        android:text="5"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="12sp" 
        android:text="ABC"/>

</LinearLayout>

CODE

    LinearLayout button= (LinearLayout)findViewById(R.id.button_layout);
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO DO whatever you want to do here

        }
    });

For your button you can use code like this

don't forget put font in your Assets folder

 Button btnA=(Button) findViewById(R.id.button1);
 Typeface typeface = Typeface.createFromAsset(getAssets(), "yourFont.ttf");
 btnA.setText("my custom font");
 btnA.setTypeface(typeface);
 btnA.setTextSize(20);//as per your size

and for more reference see this

do as your second button if this helps let me know thanks...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!