我使用了Reuben Scratton在这个问题中的新答案。当我将其粘贴到我的代码中时,
谢谢!以下是我的.java页面上的代码。
addOnGlobalLayoutListener(new OnGlobalLayoutListener()
、onGlobalLayout()
和activityRootView
(heightDiff后)下面出现红色波浪线。请帮我找出问题所在。谢谢!以下是我的.java页面上的代码。
public class Details extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_details);
Intent intent = getIntent();
}
final View activityRootView = findViewById(R.id.details);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
ImageButton backButton = (ImageButton)findViewById(R.id.back);
backButton.setImageResource(R.drawable.hide_keyboard);
}
}
});