Two line Android buttons

Ken Yee
Ken Yee
Aug 8, 2017 · 1 min read

Unfortunately, Android Button views don’t have a subtitle feature like the toolbar does if you want to have two lines. You can do a trick using Spannables to get something similar however:

            String title = "Some title";
String subTitle = "your subtitle";
int titleLength = title.length();
int subtitleLength = subTitle.length();
Spannable span = new SpannableString(title + "\n" + subTitle);
span.setSpan(new RelativeSizeSpan(0.8f), titleLength, (titleLength + subtitleLength + 1), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
button.setText(span);

Ken Yee

Written by

Ken Yee

Mobile (Native Android), Backend (Kotlin, Java, Python, Node.js, .Net), Devops (Jenkins, Vagrant, Docker) software engineer. Currently Kotlin All The Things!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade