【发布时间】:2013-01-12 22:11:42
【问题描述】:
我在this question 中使用了 Reuben Scratton 的新答案中的代码。当我将它粘贴到我的代码中时,我在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);
}
}
});
【问题讨论】:
-
请不要试图通过复制/粘贴来学习Java和Android编程。这不是一个成功的方法。浏览基础知识并从“Hello World”开始
标签: android layout listener android-softkeyboard