2013-02-08 39 views
0

朋友我只是想设置自定义字样根据我的资产/ fonts文件夹 我的Java代码如下所示自定义文本对话框实现的OnClick听众的Android

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(); 
    } 
} 

当我尝试添加像我没有工作this

它给错误

在这里,这是我的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> 

首先请您介绍如何将自定义字体添加到这种类型的上下文对话框

谢谢

回答

0

退房此链接创建自定义对话框

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

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

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

把你的字体转换下的资产目录Fonts文件夹

+0

如果在非活动类资产访问文件夹,然后你需要像context.getAssets()通过这个,你可以使用它的上下文对象 – Pratik

0

试试这个

Typeface type = Typeface.createFromAsset(getAssets(), "name.ttc"); 
dismis_dialog.setTypeface(type); 
sharedialog.setTypeface(type);