アラート ダイアログのテキストを設定する代わりに、レイアウトからカスタム ビューを設定する必要があります。その前に、ビューのフォントを変更してください。
TextView mycontent = (TextView) findViewById(R.id.yourid);
mycontent.setTypeface(Typeface.createFromAsset(getAssets(), "font.ttf")
アラート ダイアログのビューを設定するには、.setView(mycontent)
代わりに を呼び出しsetMessage()
ますが、私の知る限り、これはタイトルを変更しません。
更新
私が言っていることが理解できないようですので、ここに完全な例を示します
TextView content = new TextView(this);
content.setText("on another font");
content.setTypeface(Typeface.SANS_SERIF);
//Use the first example, if your using a xml generated view
AlertDialog.Builder myalert = new AlertDialog.Builder(this);
myalert.setTitle("Your title");
myalert.setView(content);
myalert.setNeutralButton("Close dialog", null);
myalert.setCancelable(true);
myalert.show();
これは、作成したばかりの TextView を使用しており、余白などはありません。レイアウト ファイルから簡単に作成できるものを使用すると、これらの設定をすべてカスタマイズできますが、この例ではコードでそれを行うことができます。
もちろん、フォントを必要なものに置き換えます.xmlのサンプルTextViewは次のようになります。
<TextView
android:id="@+id/yourid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="your content" />