0

朋友们我只想设置自定义字体表单我的资产/字体文件夹我的 Java 代码看起来像这样

package customtext;
import android.app.Dialog;  
import android.content.Context;  
import android.os.Bundle;  
import android.view.View;  
import android.view.Window;
import android.widget.Button;
public class Custom extends Dialog implements android.view.View.OnClickListener{  
    public Custom(Context context) {  
        super(context);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
}  
Button btn;  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.custom);  
        btn=(Button) findViewById(R.id.dismis_dialog);  
        btn.setOnClickListener(this);  
    }  
    @Override  
    public void onClick(View v) {  
        dismiss();  
    }  
}  

当我尝试像这样添加 它对我不起作用

它的错误

这是我的 XML

    <?xml version="1.0" encoding="utf-8"?>  
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   android:layout_width="fill_parent"  
   android:layout_height="fill_parent"   
   android:orientation="vertical"
   style="@style/Theme.CustomDialog"   >

       <FrameLayout
           android:layout_width="250sp"
           android:layout_height="70sp"
           android:background="#ee8f03" >
            <TextView
                 android:layout_width="180sp"  
                 android:layout_height="wrap_content"   
                 android:id="@+id/sharedialog"
                 android:text="@string/msg"  
                 android:textColor="#272b2d"
                 android:background="#ef8e01"
                 android:layout_gravity="center" >  
            </TextView>  
       </FrameLayout>

       <FrameLayout
           android:layout_width="250sp"
           android:layout_height="70sp"
           android:background="#fff" >

           <Button 
             android:layout_width="wrap_content"  
             android:layout_height="wrap_content"  
             android:layout_gravity="bottom"
             android:clickable="true" 
             android:id="@+id/dismis_dialog"  
             android:text="@string/dismis"/> 
       </FrameLayout>

  </LinearLayout>  

请您告诉如何将自定义字体添加到这种类型的上下文对话框中

谢谢

4

2 回答 2

0

试试这个

Typeface type = Typeface.createFromAsset(getAssets(), "name.ttc");
dismis_dialog.setTypeface(type);
sharedialog.setTypeface(type);
于 2013-02-08T06:22:30.277 回答
0

查看此链接以创建自定义对话框

http://www.mkyong.com/android/android-custom-dialog-example/

您也可以像这样设置自定义字体

Typeface type = Typeface.createFromAsset(getAssets()/fonts, "myfonts.ttc");
youTextView.setTypeface(type);

将您的字体放入资产目录下的字体文件夹中

于 2013-02-08T06:24:23.237 回答