Skip to main content

Posts

Android : Password Show Hide EditText

Please follow below steps to accomplish the show/hide functionality on EditText Add EditText to your text file <EditText android :id= "@+id/password" android :layout_width= "wrap_content" android :layout_height= "wrap_content" android :inputType= "textPassword" android :ems= "10" android :drawableRight= "@drawable/eye" android :layout_centerHorizontal= "true" /> Add OnTouchListener for EditText editText = findViewById(R.id. password ) ; editText .setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch (View v , MotionEvent event) { final int DRAWABLE_LEFT = 0 ; final int DRAWABLE_TOP = 1 ; final int DRAWABLE_RIGHT = 2 ; final int DRAWABLE_BOTTOM = 3 ; if (event.getAction() == MotionEvent. ACTION_DOWN ) { if (event.getRawX() >= ( editText .getRigh...
Recent posts

Android : Toggle button like iOS

Please follow below steps to accomplish toggle button like iOS using xml only. Step 1: Add switch control on your layout file. <Switch android :id= "@+id/mySwitch" android :layout_width= "wrap_content" android :layout_height= "wrap_content" android :thumb= "@drawable/selector " android :track= "@drawable/track" /> Step 2 : Create selector.xml in drawable folder <? xml version= "1.0" encoding= "utf-8" ?> <selector xmlns: android = "http://schemas.android.com/apk/res/android" > <item android :state_enabled= "false" > <shape android :shape= "oval" > <solid android :color= "#838282" /> <stroke android :width= "@dimen/switch_stroke_width" android :color= "#69696...

Android : How to add SHA-1 to firebase FCM

1. Generate for Debug purpose on MAC keytool - list - v - alias androiddebugkey - keystore ~ /.android/ debug . keystore - storepass android - keypass android 1. Generate for Release purpose on MAC keytool - list - v - alias exampleapp - keystore ~ /example/release . keystore - storepass android - keypass android

Android : Confirmation Alert Dialog with Yes and No Button

Call this method to show confirmation alert dialog. public static void alertC onfirmation( final Activity context) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setIcon(R.drawable.ic_lock_off); builder.setTitle( "Exit" ); builder.setMessage( "Are you sure?" ) .setCancelable( false ) .setPositiveButton( "Yes" , new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //TODO your yes action } }) .setNegativeButton( "No" , new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //TODO your no action } }); AlertDialog alert = builder.create(); alert.show(); }

Android : Custom Toast Message

public static void showCustomToast(Context context, String message, int duration) { Toast t = new Toast(context); LinearLayout view = new LinearLayout(context); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.gravity = Gravity.CENTER; view.setLayoutParams(params); view.setBackgroundResource(R.drawable.popup); LayoutParams txtparam = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f ); txtparam.gravity = Gravity.CENTER; TextView txt = new TextView(context); txt.setTextAppearance(context, android.R.attr.textAppearanceLarge); txt.setPadding( 20 , 0 , 20 , 0 ); txt.setTextColor(Color.WHITE); txt.setGravity(Gravity.CENTER); txt.setLayoutParams(txtparam); txt.setText(message); view.addView(txt); t.setView(view); t.setGravity(Gravity.CENTER, 0 , 0 ); t.setDuration(duration); t.show...

Android : How to check app is in foreground or at background

1. First add the GET_TASKS Manifest.permission to your AndroidManifest.xml 2. Use the below method to check if the app is in background or foreground 3. This method will return true if the app is in foreground. JAVA : protected Boolean isAppAtForeground(Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context. ACTIVITY_SERVICE ); List<activitymanager .runningtaskinfo= "" > tasks = activityManager.getRunningTasks(Integer. MAX_VALUE ); for (ActivityManager.RunningTaskInfo task : tasks) { if (context.getPackageName().equals(tasks.get( 0 ).topActivity.getPackageName())) return true ; } return false ; } KOTLIN : protected fun isAppAtForeground(context: Context): Boolean? { val activityManager = context.getSystemService(Context. ACTIVITY_SERVICE ) as ActivityManager val tasks = activityManager.getRunningTasks(Integer. MAX_VALUE ) for (task in tasks) { if (...