Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9075979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:00:03+00:00 2026-06-16T19:00:03+00:00

Where should I put this code Button txt = (Button) findViewById(R.id.button1); Typeface font =

  • 0

Where should I put this code

 Button txt = (Button) findViewById(R.id.button1);  
    Typeface font = Typeface.createFromAsset(getAssets(), "customfont.ttf");  
    txt.setTypeface(font);

so I can change the font of the text that is displayed on my button?
I just want the font on the button changed. I am not trying to change the font in the alert dialog box. I just don’t know where to put the code to change the button font. I already have the custom font placed inside a “fonts” folder located in assets.

Here is the xml part of the button:

<Button
    android:id="@+id/button1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:onClick="alertBtn"
    android:text="Click for message" 
    android:textSize="22sp"
    />

Here is the code of my project:

package com.test.hellothere;

import android.app.Activity;
import android.app.AlertDialog;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class HelloThereActivity extends Activity implements View.OnClickListener{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


    }

    public void onClick(View v){}

    public void alertBtn(View v){

        new AlertDialog.Builder(this)
        .setTitle("Hello")
        .setMessage("Hello There!")
        .setNeutralButton("Go Back", null)
        .show();
    }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:00:06+00:00Added an answer on June 16, 2026 at 7:00 pm

    put your code inside onCreate of Activity after setContentView as:

    public class HelloThereActivity extends Activity implements View.OnClickListener{
        /** Called when the activity is first created. */
     Button txt;
     Typeface font;
      @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
           txt = (Button) findViewById(R.id.button1);  
    
           // call here for setting font 
           setfonttoView(txt);
    
           //.....same for other buttons
        }
      public void setfonttoView(Button button){
           font = Typeface.createFromAsset(getAssets(), "customfont.ttf");  
           button.setTypeface(font);
        }
    
      //your code here...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code for update: public Boolean update() { try { data.put(ContactsContract.Groups.SHOULD_SYNC, true);
This answer suggested i should put my data in JS instead of a textarea.
Hi I have this in my application : The question is, should I put
Possible Duplicate: PHP detecting request type (GET, POST, PUT or DELETE) This should be
I have the following code which should put programs startable in Bash. if [
I'm going to develop a Firefox extension which should put a button in the
I want to rewrite this code to Backbone.js, how should I do that? app/assets/javascripts/views/plots/plots_index.js.coffee
Using this the samples located here I've put this together: The code is located
I just want to ask how should I put my image (dynamically) in this
consider this code. when button is clicked 'active' class is added to this, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.