Solution 1:
View activityRootView = fragmentView.findViewById(R.id.root_view);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener( new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
activityRootView.getWindowVisibleDisplayFrame(r);
int screenHeight = activityRootView.getRootView().getHeight();
Log.e("screenHeight",String.valueOf(screenHeight));
int heightDiff = screenHeight - (r.bottom - r.top);
Log.e("heightDiff",String.valueOf(heightDiff));
boolean visible = heightDiff > screenHeight / 3;
Log.e("visible",String.valueOf(visible));
if(visible)
{ if true ,do your stuff here !}
else
{ else, do your stuff here }
}
});
Solution 2:
View activityRootView = fragmentView.findViewById(R.id.root_view);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > 150)
{ // if more than 150 pixels, its probably a keyboard...
do your stuff , if keyboard visible
}
else
{
}
}
});
View activityRootView = fragmentView.findViewById(R.id.root_view);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener( new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
activityRootView.getWindowVisibleDisplayFrame(r);
int screenHeight = activityRootView.getRootView().getHeight();
Log.e("screenHeight",String.valueOf(screenHeight));
int heightDiff = screenHeight - (r.bottom - r.top);
Log.e("heightDiff",String.valueOf(heightDiff));
boolean visible = heightDiff > screenHeight / 3;
Log.e("visible",String.valueOf(visible));
if(visible)
{ if true ,do your stuff here !}
else
{ else, do your stuff here }
}
});
Solution 2:
View activityRootView = fragmentView.findViewById(R.id.root_view);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > 150)
{ // if more than 150 pixels, its probably a keyboard...
do your stuff , if keyboard visible
}
else
{
}
}
});
I Need Send SMS BY ONE SIMCARD, IF YOU CAN PLEASE CONTACT ME mayihelpu789@gmail.com
ReplyDeleteNeed a template for Clothing website? TemplateMonster has you covered with many Clothing website templates to pick from. Start your website today!
ReplyDelete