gpt4 book ai didi

android - android输入数据时TabHost栏在键盘上方

转载 作者:搜寻专家 更新时间:2023-11-01 07:55:13 24 4
gpt4 key购买 nike

在我的应用程序中,我使用 tabhost 创建一个菜单栏,如下所示:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />

<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />

<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal" />
</LinearLayout>

 tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
tabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);

tabHost.addTab(tabHost.newTabSpec("home").setIndicator("Home"),HomeFragment.class, null);
tabHost.addTab(tabHost.newTabSpec("attraction").setIndicator("Attraction"),AttractionFragment.class, null);
tabHost.addTab(tabHost.newTabSpec("schedule").setIndicator("Schedule"),ScheduleFragment.class, null);
tabHost.addTab(tabHost.newTabSpec("map").setIndicator("Map"),MapViewFragment.class, null);
tabHost.addTab(tabHost.newTabSpec("weather").setIndicator("Weather"),WeatherFragment.class, null);

enter image description here

问题是,当键盘显示时,标签栏在键盘上方,我已经设置了这样的输入模式:

android:windowSoftInputMode="stateHidden"

enter image description here

如何在键盘显示时隐藏标签栏?谢谢

最佳答案

onConfigurationChanged 方法可以被覆盖以处理运行时更改,您可以使用 tabHost.setVisibility( View.GONE ); Handling Runtime Change

// from the link above
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks whether a hardware keyboard is available
if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
tabHost.setVisibility( View.GONE );

}
else if (newConfig.hardKeyboardHidden ==Configuration.HARDKEYBOARDHIDDEN_YES) {
tabHost.setVisibility( View.VISIBLE );
}
}

你可以在每个你想隐藏tabhost的activity上添加这段代码,你只需要传递你布局的Rootview id。

public final int SOFTKEYBOARDHEIGHT=100;
final View activityRootView = findViewById(R.id.YOURROOTVIEW);
activityRootView.getViewTreeObserver()
.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > SOFTKEYBOARDHEIGHT) {
tabHost.setVisibility( View.GONE );
}
}
});

关于android - android输入数据时TabHost栏在键盘上方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28710609/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com