【问题标题】:android-keyboard does not appear in child activity of TabActivityandroid-keyboard 没有出现在 TabActivity 的子活动中
【发布时间】:2013-09-21 10:15:52
【问题描述】:

代码sn-p:

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。现在在 NewPostActivity 我只有一个编辑文本,当我点击 Edittext 时,键盘似乎没有写入该编辑文本。 那么键盘外观应该怎么做呢? 请回复....

【问题讨论】:

    标签: android android-activity tabs


    【解决方案1】:
    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;
            }
        });
    

    这里rel是xml中的顶层布局

    【讨论】:

    • 感谢您的回复......但它不工作......我在 android2.3.6 版本中遇到问题......&在 android4.0 中它的工作完美...... :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    • 2014-01-30
    相关资源
    最近更新 更多