Sometimes there is a need to access recourses from static methods.
In order to do this we need to pass along the Context to the method and use getString from that Context.
Example:
package com.f15ijp.android.test; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.view.WindowManager; public class Help { public static AlertDialog helpDialog(Context theContext, String helpMessage){ AlertDialog alertDialog = new AlertDialog.Builder(theContext).create(); alertDialog.setTitle("Help"); alertDialog.setMessage(helpMessage); alertDialog.setButton(theContext.getString(R.string.close_help_btn), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { return; } }); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(alertDialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; /*by calling alertDialog.show() now and then again after setAttributes the background * the background activity is replaced by a black box. * If this first alertDialog.show() is removed then the (current) acitivity is used as a background. */ alertDialog.show(); alertDialog.getWindow().setAttributes(lp); return alertDialog; } } |