【问题标题】:android edittext characters alignment, colors and sizeandroid edittext 字符对齐、颜色和大小
【发布时间】:2018-04-15 08:35:29
【问题描述】:

在我的应用程序中, 应该允许用户更改对齐、颜色、大小和其他文本属性,但它实现了对所有文本内容的对齐更改,当我触摸开箱时,大小和颜色将返回到第一个视图

所以我想知道如何解决这个问题。

【问题讨论】:

    标签: java android android-layout android-edittext


    【解决方案1】:

    你必须使用 spandable 。

    为您的文本颜色使用 ForegroundColorSpan

    SpannableStringBuilder ssb = new SpannableStringBuilder("Hello Everyone");
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(
            context.getResources()
            // Specify your color
            .getColor(R.color.your_font_color));
    realPrice.setSpan(colorSpan,
             0, // Start index of the single word
             4, // End index of the single word
            Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    yourEditText.setText(ssb);
    

    对于您的文本大小,请这样做:

    String s= "Hello Everyone";
     SpannableString ss1=  new SpannableString(s);
    ss1.setSpan(new RelativeSizeSpan(2f), 0,5, 0); // set size
    ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, 5, 0);// set color
    TextView tv= (TextView) findViewById(R.id.textview);
    tv.setText(ss1); 
    

    输入你的字符串而不是“大家好”

    【讨论】:

      猜你喜欢
      • 2023-03-22
      • 1970-01-01
      • 2013-05-28
      • 2012-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-12
      • 2012-04-20
      相关资源
      最近更新 更多