我在第一次启动时使用复制的代码显示AlertDialog,但并未完全理解,但它作为EULA很有用。我想用较小的字体显示冗长的法律文本。文本从RES/ASSETS目录中的文件加载。AlertDialog文本属性
我猜标准AlertDialog有一个内置的TextView?如果是这种情况,那么我需要访问它,然后更改TextView的TextSize属性?感谢您的任何建议。
我在第一次启动时使用复制的代码显示AlertDialog,但并未完全理解,但它作为EULA很有用。我想用较小的字体显示冗长的法律文本。文本从RES/ASSETS目录中的文件加载。AlertDialog文本属性
我猜标准AlertDialog有一个内置的TextView?如果是这种情况,那么我需要访问它,然后更改TextView的TextSize属性?感谢您的任何建议。
我不知道如何使用标准AlertDialog中提供的TextView来做到这一点。但是很容易添加自己的TextView,你可以控制它的大小(和其他方面)。
TextView myView = new TextView(getApplicationContext());
myView.setText("blahblahblahblahblahblahblahblah");
myView.setTextSize(10);
AlertDialog.Builder builder = new AlertDialog.Builder(YOURACTIVITY.this);
builder.setView(myView)
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// put your code here
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// put your code here
dialog.cancel();
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
我想你不必为Eula使用警报对话框。这是一个单独的过程。 你可以去这个链接创建EULA。
http://bees4honey.com/blog/tutorial/adding-eula-to-android-app/
非常感谢。 – paulpo 2010-12-24 01:14:19
要使用外部文件的AlertDialog
的内容尝试:
`start_builder.setMessage(readRawTextFile(CONTEXT, R.raw.tos))
.setCancelable(false)
.setTitle(R.string.TOS_TITLE)
.setPositiveButton("Accept", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id){
dialog.cancel(); // ToS accepted, run the program.
}
}) ...`
和readRawTextFile()
方法被定义为:
`/**
* Helper method to read in the text based files that are used to populate
* dialogs and other information used in the program.
*
* @param contex The context of the method call
* @param resId The resource ID of the text file from the \src\raw\ directory and registered
* in R.java.
* @return String Returns a String of the text contained in the resource file.
*/
public static String readRawTextFile(Context contex, int resId)
{
InputStream inputStream = contex.getResources().openRawResource(resId);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i;
try {
i = inputStream.read();
while (i != -1)
{
byteArrayOutputStream.write(i);
i = inputStream.read();
}
inputStream.close();
} catch (IOException e) {
return null;
}
return byteArrayOutputStream.toString();
}`
的最后一个片段不是我的,look here for the SO question that I got it from。非常适合展示我的EULA。只需将您的源文本文件移动到raw
目录并开始营业!
非常感谢。解决了我的问题。我非常感谢帮助。 – paulpo 2010-12-24 01:13:53