朋友我只是想設置自定義字樣根據我的資產/ 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>
首先請您介紹如何將自定義字體添加到這種類型的上下文對話框
謝謝
如果在非活動類資產訪問文件夾,然後你需要像context.getAssets()通過這個,你可以使用它的上下文對象 – Pratik