Textview in Android displays circle background or sets fillet method

preface

After learning Android for so long and using textview for so long, we have never used to add a background to textview, or add a border to textview, or how to set the shape of textview. It is used when writing code today. How to set the background, shape and border of textview in Java code.

The method is as follows:

Next, let's take a look at how to set the background color of textview in Java code. In fact, it's very simple in one sentence.

We can directly call the drawable file in the XML layout file. The code is as follows:

When setting the background, we all know to use the setbackgroundcolor () method. However, the parameters in the method must be values in RGB HTML format. If we use drawable, it will prompt that drawable is of type int. (in fact, if possible, we might as well use the ImageView component, which is better than textview).

Let's take a look at how to make textview display borders and how to make it display circles. Here, we need to create a new. XML file in drawable.

This is just a circle. The stroke attribute sets the border color and width. The XML layout displays the style shown in the figure:

Finally, we can use drawable call in XML file.

In XML, we can not only set the circle, but also set the fillet,

We are introducing some knowledge about shape:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>