Java tutorial
//package com.java2s; /** * Copyright 2015 bingoogolapple * <p/> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * <p/> * http://www.apache.org/licenses/LICENSE-2.0 * <p/> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.graphics.Typeface; import android.text.SpannableString; import android.text.Spanned; import android.text.TextUtils; import android.text.style.AbsoluteSizeSpan; import android.text.style.ForegroundColorSpan; import android.text.style.StyleSpan; import android.util.TypedValue; import android.view.View; import android.widget.TextView; public class Main { public static void setTitle(TextView titleTv, int titleColor, int titleTextSize, int messageColor, int messageTextSize, CharSequence title, CharSequence message) { titleTv.setMinHeight(titleTextSize * 3); if (!TextUtils.isEmpty(title) && TextUtils.isEmpty(message)) { titleTv.setTextColor(titleColor); titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize); titleTv.getPaint().setFakeBoldText(true); titleTv.setText(title); } else if (TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) { titleTv.setTextColor(messageColor); titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, messageTextSize); titleTv.setText(message); } else if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) { SpannableString titleSs = new SpannableString(title + "\n" + message); titleSs.setSpan(new ForegroundColorSpan(titleColor), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); titleSs.setSpan(new AbsoluteSizeSpan(titleTextSize), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); titleSs.setSpan(new StyleSpan(Typeface.BOLD), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); titleSs.setSpan(new ForegroundColorSpan(messageColor), title.length(), titleSs.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); titleSs.setSpan(new AbsoluteSizeSpan(messageTextSize), title.length(), titleSs.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); titleTv.setText(titleSs); titleTv.setLineSpacing(0.0f, 1.2f); } else { titleTv.setVisibility(View.GONE); } } }