How to create a TextArea in Android

前端 未结 11 1876
醉话见心
醉话见心 2021-02-06 22:16

How do I display a TextArea for my android project? From xml, the only choice is TextField, multi lined. But thats editable. I need a TextArea which is only for displaying messa

11条回答
  •  醉酒成梦
    2021-02-06 22:41

    Use TextView inside a ScrollView to display messages with any no.of lines. User can't edit the text in this view as in EditText.

    I think this is good for your requirement. Try it once.

    You can change the default color and text size in XML file only if you want to fix them as below:

    
    

    or if you want to change dynamically whenever you want use as below:

    TextView textarea = (TextView)findViewById(R.id.tv);  // tv is id in XML file for TextView
    textarea.setTextSize(20);
    textarea.setTextColor(Color.rgb(0xff, 0, 0));
    textarea.setTypeface(Typeface.SERIF, Typeface.ITALIC);
    

提交回复
热议问题