Jump to content
  • Hello visitors, welcome to the Hacker World Forum!

    Red Team 1949  (formerly CHT Attack and Defense Team) In this rapidly changing Internet era, we maintain our original intention and create the best community to jointly exchange network technologies. You can obtain hacker attack and defense skills and knowledge in the forum, or you can join our Telegram communication group to discuss and communicate in real time. All kinds of advertisements are prohibited in the forum. Please register as a registered user to check our usage and privacy policy. Thank you for your cooperation.

    TheHackerWorld Official

自定义 Android 控件 TextView 的形状



Recommended Posts

在 drawable 文件夹中新建一个 xml 文件,专门定义 TextView 的形状,称之为形状可绘制对象。在布局 xml 文件中添加 background 属性,引用 drawable 新建的 xml 文件:

布局 xml 文件:

  android:background="@drawable/circle_text_view" />

drawable 新建的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  <solid android:color="#6BB864" />


形状可绘制对象是一种在 XML 文件中定义的通用形状。

android:shape 定义形状的类型,有效值包括:

"rectangle" 用于填充所包含视图的矩形。这是默认形状。
"oval" 适应所包含视图尺寸的椭圆形状。
"line" 跨越所包含视图宽度的水平线。此形状需要 <stroke> 元素定义线宽。
"ring" 环形。

android:useLevel:通常应为 false,否则形状可能不会显示。

更多属性值以及说明请看官方文档:可绘制资源 - 形状可绘制对象。

Link to post
Link to comment
Share on other sites


discussion group

discussion group

    You don't have permission to chat.
    • Recently Browsing   0 members

      • No registered users viewing this page.
    • Create New...