【问题标题】:How to get text from EditText and Show on ActionBar?如何从 EditText 获取文本并在 ActionBar 上显示?
【发布时间】:2016-08-12 07:21:39
【问题描述】:

我有 EditText,用户可以在其中输入他们的帐号。现在我想要什么,当用户停止在 EditText 中输入他的帐号时,我想在 ActionBar 中显示该帐号。我怎样才能做到这一点?

【问题讨论】:

标签: android android-edittext android-actionbar fragment


【解决方案1】:

尝试使用TextWatcher。像这样的:

editText.addTextChangedListener(new TextWathcer(){
    void beforeTextChanged(CharSequence s, int start, int count, int after){}
    void onTextChanged(CharSequence s, int start, int before, int count){}
    void afterTextChanged(Editable s){
        getSupportActionBar().setTitle(s.getText().toString());
    }
});

【讨论】:

    【解决方案2】:

    此代码可能有效:

    getSupportActionBar().setTitle(editText.getText().toString());
    

    如果你想在action bar的右边设置标题,建议使用Toolbar,你可以自定义布局。

    【讨论】:

    • 感谢 L. Swifter。标题已经显示在操作栏上我想显示这些标题的右侧。
    • @MoinKhan 最好使用Toolbar 而不是ActionBar。 :)
    猜你喜欢
    • 2018-02-23
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-21
    相关资源
    最近更新 更多