Android 框架布局的键盘问题
我的版面上有一个EditText,它是一个框架版面,问题是当我在EditText中输入完一些数据后,我按下手机上的后退按钮来隐藏键盘,它会一直显示键盘的阴影,直到我按下活动中的任何位置 我怎样才能解决这个问题 下面是我按下后退按钮隐藏键盘后发生的情况,我必须再次按下活动以使黑色阴影消失。(检查底部的黑色阴影) AndroidManifest.xmlAndroid 框架布局的键盘问题,android,xml,Android,Xml,我的版面上有一个EditText,它是一个框架版面,问题是当我在EditText中输入完一些数据后,我按下手机上的后退按钮来隐藏键盘,它会一直显示键盘的阴影,直到我按下活动中的任何位置 我怎样才能解决这个问题 下面是我按下后退按钮隐藏键盘后发生的情况,我必须再次按下活动以使黑色阴影消失。(检查底部的黑色阴影) AndroidManifest.xml <activity android:name="com.example.MainActivity" and
<activity
android:name="com.example.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" >
</activity>
activty_main.xml
<com.example.layout.MainLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/activity_main_content_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout></com.example.layout.MainLayout>
更新:-
MainActivity.Java
public class MainActivity extends FragmentActivity {
// The MainLayout which will hold both the sliding menu and our main content
// Main content will holds our Fragment respectively
MainLayout mainLayout;
// ListView menu
private ListView lvMenu;
private String[] lvMenuItems;
// Menu button
TextView btMenu;
// Title according to fragment
TextView tvTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Inflate the mainLayout
mainLayout = (MainLayout)this.getLayoutInflater().inflate(R.layout.activity_main, null);
setContentView(mainLayout);
lvMenuItems = getResources().getStringArray(R.array.menu_items);
lvMenu = (ListView) findViewById(R.id.activity_main_menu_listview);
lvMenu.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, lvMenuItems));
lvMenu.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
onMenuItemClick(parent, view, position, id);
}
});
// Get menu button
btMenu = (TextView) findViewById(R.id.activity_main_content_button_menu);
btMenu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Show/hide the menu
toggleMenu(v);
}
});
// Get title textview
tvTitle = (TextView) findViewById(R.id.activity_main_content_title);
// Add FragmentMain as the initial fragment
FragmentManager fm = MainActivity.this.getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
FragmentHome fragment = new FragmentHome();
ft.add(R.id.activity_main_content_fragment, fragment);
ft.commit();
}
public void toggleMenu(View v){
mainLayout.toggleMenu();
}
// Perform action when a menu item is clicked
private void onMenuItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedItem = lvMenuItems[position];
String currentItem = tvTitle.getText().toString();
// Do nothing if selectedItem is currentItem
if(selectedItem.compareTo(currentItem) == 0) {
mainLayout.toggleMenu();
return;
}
FragmentManager fm = MainActivity.this.getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment fragment = null;
String[] menu = getResources().getStringArray(R.array.menu_items);
if(selectedItem.compareTo(menu[0]) == 0) {
fragment = new FragmentHome();
} else if(selectedItem.compareTo(menu[1]) == 0) {
fragment = new FragmentSettings();
}
if(fragment != null) {
// Replace current fragment by this new one
ft.replace(R.id.activity_main_content_fragment, fragment);
ft.commit();
// Set title accordingly
tvTitle.setText(selectedItem);
}
// Hide menu anyway
mainLayout.toggleMenu();
}
@Override
public void onBackPressed() {
if (mainLayout.isMenuShown()) {
mainLayout.toggleMenu();
}
else {
super.onBackPressed();
}
}
@Override
public void onConfigurationChanged(Configuration config){
super.onConfigurationChanged(config);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
public类MainActivity扩展了FragmentActivity{
//主布局将容纳滑动菜单和我们的主要内容
//主要内容将分别容纳我们的片段
主布局主布局;
//列表视图菜单
私有列表视图菜单;
私有字符串[]lvMenuItems;
//菜单按钮
文本视图菜单;
//按片段命名
文本视图标题;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//给主布局充气
mainLayout=(mainLayout)this.getLayoutFlater().inflate(R.layout.activity\u main,null);
setContentView(主布局);
lvMenuItems=getResources().getStringArray(R.array.menu项);
lvMenu=(ListView)findViewById(R.id.activity\u main\u menu\u ListView);
lvMenu.setAdapter(新阵列适配器)(此,
android.R.layout.simple_list_item_1,lvMenuItems));
lvMenu.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
onMenuItemClick(父项、视图、位置、id);
}
});
//获取菜单按钮
btMenu=(文本视图)findViewById(R.id.activity\u main\u content\u button\u menu);
btMenu.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
//显示/隐藏菜单
切换菜单(v);
}
});
//获取标题文本视图
TVTTitle=(TextView)findViewById(R.id.activity\u main\u content\u title);
//添加FragmentMain作为初始片段
FragmentManager fm=MainActivity.this.getSupportFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
FragmentHome片段=新的FragmentHome();
ft.add(R.id.activity\u main\u content\u fragment,fragment);
ft.commit();
}
公共无效切换菜单(视图v){
mainLayout.toggleMenu();
}
//单击菜单项时执行操作
私有void onMenuItemClick(AdapterView父项、视图、int位置、长id){
字符串selectedItem=lvMenuItems[position];
字符串currentItem=tvTitle.getText().toString();
//如果selectedItem是currentItem,则不执行任何操作
如果(选择编辑项比较到(当前项)==0){
mainLayout.toggleMenu();
返回;
}
FragmentManager fm=MainActivity.this.getSupportFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
片段=空;
String[]menu=getResources().getStringArray(R.array.menu_项);
如果(选择编辑项比较到(菜单[0])==0){
fragment=新的FragmentHome();
}else if(选择editem.compareTo(菜单[1])==0){
fragment=新的FragmentSettings();
}
if(片段!=null){
//用这个新片段替换当前片段
ft.replace(R.id.activity\u main\u content\u fragment,fragment);
ft.commit();
//相应地设置标题
tvTitle.setText(selectedItem);
}
//还是隐藏菜单
mainLayout.toggleMenu();
}
@凌驾
public void onBackPressed(){
if(mainLayout.ismenuShowed()){
mainLayout.toggleMenu();
}
否则{
super.onBackPressed();
}
}
@凌驾
公共无效OnConfiguration已更改(配置){
super.onConfigurationChanged(配置);
setRequestedOrientation(ActivityInfo.SCREEN\u ORIENTATION\u Picture);
}
}我终于做到了。
我不得不添加我的片段
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(MYeditText.getWindowToken(), 0);
我有同样的问题,我解决了它,而把下面的代码在框架布局的主要活动
<activity
android:name="com.shane.pir.carhire.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout"
android:windowSoftInputMode="adjustPan" >
</activity>
自定义布局中有什么com.example.layout.mainloayout
我已经添加了代码,请检查为什么您使用com.example.layout.mainloayout
(顺便说一句,它不是您的MainActivity类)而不是类似LinearLayout
?这是我的主要活动,我正在为滑动菜单使用自定义框架布局