Shows alert dialog with Custom font in message. - Android User Interface

Android examples for User Interface:Alert Dialog

Description

Shows alert dialog with Custom font in message.

Demo Code

/*/*ww  w .  j a va2s  . c  om*/
 * Copyright 2015 Yuriy Yunikov
 *
 * 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
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Build;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Main{
    /**
     * Shows alert dialog with Roboto font in message.
     *
     * @param context context
     * @param dialog dialog on which to set Roboto font
     */
    public static void showRobotoDialog(final Context context,
            final AlertDialog dialog) {
        dialog.show();
        final TextView tvMessage = (TextView) dialog
                .findViewById(android.R.id.message);
        final Typeface roboto = Typeface.createFromAsset(
                context.getAssets(), "fonts/Roboto-Regular.ttf");
        final Typeface robotoLight = Typeface.createFromAsset(
                context.getAssets(), "fonts/Roboto-Light.ttf");

        final Button button1 = (Button) dialog
                .findViewById(android.R.id.button1);
        final Button button2 = (Button) dialog
                .findViewById(android.R.id.button2);
        final Button button3 = (Button) dialog
                .findViewById(android.R.id.button3);

        button1.setTypeface(robotoLight);
        button2.setTypeface(robotoLight);
        button3.setTypeface(robotoLight);
        tvMessage.setTypeface(roboto);
    }
}

Related Tutorials