Close/hide the Android Soft Keyboard everywhere you want, Change Image of ImageView programmatically in Android, Height of status bar in Android

Close/hide the Android Soft Keyboard everywhere you want

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Change Image of ImageView programmatically in Android

imageView.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.your_image));

Height of status bar in Android

public static int getStatusBarHeight(Context context) {
    int result = 0;
    int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = context.getResources().getDimensionPixelSize(resourceId);
    }
    return result;
}

Underline TextView with only one line of code

textView.setPaintFlags(textView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

Strike-through a TextView

if (isCancel) {
    textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
} else {
    textView.setPaintFlags(textView.getPaintFlags() & (~ Paint.STRIKE_THRU_TEXT_FLAG));
}

Call method after regular interval of time

// create timer
private Timer myTimer;

// use it
myTimer = new Timer();
myTimer.schedule(new TimerTask() {
    @Override
    public void run() {
        doSomething();
    }
}, 0, 5000); // delay: 0second, perios: 5seconds

// stop it
@Override
public void onStop(){
    super.onStop();
    if (myTimer != null) {
        myTimer.cancel();
    }
}

 


Leave a Reply

Your email address will not be published. Required fields are marked *