2013-09-21 42 views
0

代码片段:Android的键盘没有出现在TabActivity的子活动

public class home extends TabActivity implements OnTabChangeListener{ 

private static final String HOME_SPEC = ""; 
private static final String PROFILE_SPEC = ""; 
private static final String NEWPOST_SPEC = ""; 
private static final String SETTINGS_SPEC = ""; 
private TabHost tabHost; 
private TextView header; 
int s,c; 
private Typeface tf; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.home); 

    tabHost = getTabHost(); 

    TabSpec newpostSpec = tabHost.newTabSpec(NEWPOST_SPEC); 
    newpostSpec.setIndicator(NEWPOST_SPEC, getResources().getDrawable(R.drawable.icon_post_tab)); 
    Intent newpostIntent = new Intent(home.this,NewPostActivity.class); 
    newpostSpec.setContent(newpostIntent); 

    tabHost.addTab(loginSpec); 
    tabHost.addTab(newpostSpec); 

    tabHost.setOnTabChangedListener(this); 
    for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) 
     { 
      tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.TRANSPARENT); 

     } 

     } 

    @Override 
    public void onTabChanged(String tabId) { 
     // TODO Auto-generated method stub 
     for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) 
     { 
      tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.TRANSPARENT); 
     } 

     tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.TRANSPARENT); 
    } 

} 

上面的代码我已经使用TabActivity.Now在NewPostActivity我只有一个EditText上&当我点击EDITTEXT,键盘没有出现在该编辑文本中编写。 所以我应该为键盘的外观做些什么? 请回复....

回答

0
For showing the keyboard implicitly do like this 

// for showing the soft keyboard on click of edit text 
    InputMethodManager mgr = (InputMethodManager)  getSystemService(Context.INPUT_METHOD_SERVICE); 
    // only will trigger it if no physical keyboard is open 
    mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 


and to hide the keyboard it when touched somewhere outside of the edit text. 

rel.setOnTouchListener(new OnTouchListener() { 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 

      InputMethodManager mgr = (InputMethodManager)  getSystemService(Context.INPUT_METHOD_SERVICE); 
      mgr.hideSoftInputFromWindow(editText.getWindowToken(), 0); 
      return false; 
     } 
    }); 

这里相对是XML顶部布局

+0

感谢响应...但它在android2.3.6版本不工作....我面对的问题。 ..&在android4.0中它的工作完美... :( – dhrut