Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PreferenceUtils {
- private PreferenceUtils(){}
- public static int setResources (String string, String string2, Context context){
- return context.getResources().getIdentifier(string, string2, context.getPackageName());
- }
- public static void dialogOption(final Activity activity){
- Context context = activity;
- if (!Boolean.valueOf((boolean) PreferenceManager.getDefaultSharedPreferences(context).getBoolean("disable_dialog_key", false)).booleanValue()) {
- return;
- }else{
- tampilkanDialog(activity);
- }
- }
- public static void tampilkanDialog(final Activity activity){
- final AlertDialog.Builder adb = new AlertDialog.Builder(activity);
- LayoutInflater adbInflater = LayoutInflater.from(activity);
- View view = adbInflater.inflate(setResources("dialog_about", "layout", activity), null);
- adb.setView(view);
- adb.setNeutralButton("Dismiss", new DialogInterface.OnClickListener() {
- @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
- public void onClick(DialogInterface dialog, int which) {
- return;
- }
- });
- adb.show();
- }
- }
- ==== Letakan di activity dimana mau ditampilkan dialog
- PreferenceUtils.dialogOption(this);
- contoh :
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- PreferenceUtils.dialogOption(this);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment