【问题标题】:Android - Bolding Part of Text in EditTextAndroid - EditText 中的粗体部分文本
【发布时间】:2015-11-29 16:29:55
【问题描述】:

有一个类似的答案here,但它没有说明我要问什么。

我的 Android 视图中有一个“粗体文本”选项,如果用户选择该选项,则在后面的代码中将布尔值设置为 true。

使用 TextWatcher,如何在 EditText 中的特定点之后将用户键入的文本更改为 bold。如果用户将其关闭,则键入的文本应采用正常样式。一切都取决于布尔值。

这是我目前所拥有的:

Boolean isBolded = false;

// Code that turns the bold option true and false...

contentBox = (EditText) findViewById(R.id.contentBox);
contentBox.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if(isBolded)
                {
                   //Start bolding the text typed after that point
                }
                else
                {
                   //Stop styling the text typed after that point
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

困难在于确定用户在键入时决定关闭和打开粗体的 EditText 中的点。你们有什么想法?

【问题讨论】:

标签: java android android-layout android-intent mobile


【解决方案1】:

Html.fromHtml("<b>This part will be bold</b> This won't!") 设置为文本。

【讨论】:

  • 我的问题是找出用户决定在哪里打开粗体以及在哪里关闭它并在编辑文本中获得该位置
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-18
  • 2020-07-26
  • 2017-05-22
  • 2015-01-11
  • 1970-01-01
相关资源
最近更新 更多