Reputation: 29
I show an AlertDialog on the first start-up using code I copied and don't fully understand, but it works great as a EULA. I want to show the longwinded legal text in a smaller font. Text is loaded from a file in the RES/ASSETS directory.
I'm guessing the standard AlertDialog has a built-in TextView? If that's the case then I need to get access to that then change the TextSize property of the TextView? Thanks for any suggestions.
Upvotes: 0
Views: 3280
Reputation: 1858
To use an external file for the contents of the AlertDialog
try this:
`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.
}
}) ...`
and the readRawTextFile()
method is defined as:
`/**
* 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();
}`
The last snippet is not mine, look here for the SO question that I got it from. Works great for displaying my EULA. Just move your source text file to the raw
directory and your in business!
Upvotes: 1
Reputation: 606
i think u don't have to use an alert dialog for Eula. there is a separate process for this. u can go for this link for creating EULA.
http://bees4honey.com/blog/tutorial/adding-eula-to-android-app/
Upvotes: 1
Reputation: 46856
I don't know of a way to do this with the TextView that comes in the standard AlertDialog. But it is easy to add your own TextView which you can control the size(and every other aspect) of.
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();
Upvotes: 2