下面是我的代码工作正常唯一的问题是它显示如此小的字体大小的对话框标题我怎么会改变字体大小任何想法???
Dialog dialog2;
dialog2 = new Dialog(context);
View vLoad = LayoutInflater.from(ActivityHome.this).inflate(R.layout.timer, null);
dialog2.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog2.setContentView(vLoad);
dialog2.setTitle( Html.fromHtml("<font color='#ffffff' > Due Alert</font>"));
dialog2.show();
答案 0 :(得分:9)
试试这个:
TextView title = new TextView(context);
title.setText("Due Alert");
title.setGravity(Gravity.CENTER);
title.setTextSize(30);
title.setBackgroundColor(Color.GRAY);
title.setTextColor(Color.WHITE);
dialog2.setCustomTitle(title);
答案 1 :(得分:0)
试试这个,
dialog2.setTextSize(14);
答案 2 :(得分:0)
你有另一个选择,为你的对话框设计一个xml layout
你如何在活动中调用它并将其调用
示例xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="215dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/custom_alert"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_header"
android:layout_width="fill_parent"
android:layout_height="26dp"
android:gravity="center"
android:text="@string/oops"
android:textColor="#3f3f3f"
android:textSize="15sp"
android:textStyle="bold"
/>
<TextView
android:id="@+id/tv_description"
android:layout_width="fill_parent"
android:layout_height="58dp"
android:layout_below="@+id/tv_header"
android:gravity="center"
android:textColor="#747474"
android:textSize="10sp"
android:typeface="sans" />
<View
android:id="@+id/separator"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_above="@+id/tv_actionbtn"
android:layout_centerVertical="true"
android:background="#b8b8b8" />
<TextView
android:id="@+id/tv_actionbtn"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_below="@+id/tv_description"
android:gravity="center"
android:textColor="#d61820"
android:textSize="15sp"
android:typeface="sans" />
custom_alert背景布局:
<corners android:color="#FFFFFF" />
<solid android:color="#FFFFFF" />
<stroke
android:width="3dip"
android:color="#FFFFFF" />
<corners
android:radius="20dip"
android:color="#FFFFFF" />
<padding
android:bottom="0dip"
android:left="0dip"
android:right="0dip"
android:top="0dip" />
这是活动代码
dialog = new Dialog(Activity.this);
dialog.setContentView(R.layout.customdialog);
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
txtHeader = (TextView) dialog.findViewById(R.id.requiredheader);
txtDiscription = (TextView) dialog.findViewById(R.id.requireddescription;
txtHeader.setText(getResources().getString(R.string.conneting_server));
txtDiscription.setText(getResources().getString(R.string.logging_in));
dialog.setCancelable(false);
dialog.show();