更改字体颜色运行的Andr​​oid [英] Changing font color runtime Android

查看:100
本文介绍了更改字体颜色运行的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的EditText获取userInput但我的问题 面对的是,我想改变字体颜色在运行,但在 同样EDITTEXT因为我能够更改字体类型,但我改变 字体颜色它改变了整个editext,但我需要改变 颜色只有specfic文本。

I am using EditText for getting userInput but the problem I am facing is that I want to change the font color at runtime but in the same Edittext as I am able to change the font type but as I change the font color it changes for the whole editext but I need to change the color for specfic text only .

和多了一个问题,问题是,使与一个EditText时 比fillparent属性的高度更为我收到光标 现在的位置在中间,但我希望它是在始终,即在顶部 开始..

And one more issue issue is that when making an edittext with the height more than the "fillparent" property I am getting the cursor postion in middle but I want it to be at the top always i.e. at the start ..

是否有任何其他部件可用,这将提供给我的解决方案 对于这两个问题呢?

Is there any other widget available which will provide me the solution for both the problems?

推荐答案

一个EditText控件中的文本的对齐方式可以通过重力控制:

Alignment of text within an EditText widget can be controlled via gravity:

editText.setGravity(Gravity.TOP);

要附加标记对象的EditText上的内容,您可以使用编辑接口:

To attach markup objects to the EditText's content you can use the Editable interface:

EditText editText = (EditText) findViewById(R.id.editview);
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append("one red word");
builder.setSpan(new ForegroundColorSpan(Color.RED), 4, 7, Spanned.SPAN_COMPOSING);
editText.setText(builder, BufferType.EDITABLE);

这篇关于更改字体颜色运行的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆