How to unbold the selected text in Edittext Android?

后端 未结 4 1718
小鲜肉
小鲜肉 2021-01-05 09:05

I am working with an edit text to support the properties of bold,italic and underline.I got succeed after selecting the text and make it bold. Now I want to remove the bold

相关标签:
4条回答
  • 2021-01-05 09:31

    in my project I use this construction

    textView.typeface = Typeface.create(textView.typeface, Typeface.NORMAL)
    
    0 讨论(0)
  • 2021-01-05 09:34

    Similar to what you have used in first onClick() instead of s.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), startSelection, endSelection, 0); use s.setSpan(new StyleSpan(android.graphics.Typeface.NORMAL), startSelection, endSelection, 0); in the second onclick().

    0 讨论(0)
  • 2021-01-05 09:38
    Button btnNormal = (Button) findViewById(R.id.btnNormal );
            btnNormal .setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                   Spannable str = etx.getText();
                   StyleSpan[] ss = str.getSpans(selectionStart, selectionEnd, StyleSpan.class);
    
           for (int i = 0; i < ss.length; i++) {
               if (ss[i].getStyle() == android.graphics.Typeface.BOLD){
                str.removeSpan(ss[i]);          
               }
           }
        etx.setText(str);
    
        }
    });    
    
    0 讨论(0)
  • 2021-01-05 09:51

    Simply use:

    Typeface.NORMAL
    

    You can check it on the Android docs.

    0 讨论(0)
提交回复
热议问题