如何以特定方式显示警告信息,这是我在警告框中显示的文字格式。
如何在警告框中显示文字,如上图中的剪辑所示,建议请。
答案 0 :(得分:1)
试试这个:
TextView tv = new TextView(this);
tv.setBackgroundColor(0xffeeeeee);
tv.setTextColor(0xff000000);
tv.setTextSize(22);
SpannableStringBuilder b = new SpannableStringBuilder();
b.append("some text here, it will be placed in several lines and then you will see the numbers:\n");
Object lms = new LeadingMarginSpan.Standard(12, 28);
int start = b.length();
b.append("1. first of all it should work and this text should be nicely indented\n");
b.append("2. if not, some bugs exist\n");
b.setSpan(lms, start, b.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
lms = new LeadingMarginSpan.Standard(-12);
start = b.length();
b.append("and this is the rest of the text");
b.setSpan(lms, start, b.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
tv.setText(b);
setContentView(tv);
答案 1 :(得分:0)
您可以创建Custom Dialog
来完成此任务。使用Relative or Linear Layout
制作图片中的布局,然后将该布局设置为Dialog
。
以下是实现此目的的示例 Android Custom Dialog Example
答案 2 :(得分:0)
在按钮内点击:
自定义对话框:
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom);
dialog.setTitle("Title...");
TextView text = (TextView) dialog.findViewById(R.id.text1);
TextView text = (TextView) dialog.findViewById(R.id.text2);
TextView text = (TextView) dialog.findViewById(R.id.text3);
text1.setText("Your Header");
text2.setText("1. body");
text3.setText("2. body");
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButton);
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
<强> custom.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" >
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your header"
android:textColor="#000000" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1. body1"
android:textColor="#000000" />
<TextView
android:id="@+id/text3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="2. body2"
android:textColor="#000000" />
<Button android:id="@+id/dialogButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Close"/>
</LinearLayout>