Java 包含标题和文本的圆形视图

Java 包含标题和文本的圆形视图,java,android,android-custom-view,Java,Android,Android Custom View,我怎么做这个?它看起来不错,我想用这样的东西 顶部的线条应与标题的结尾相对应实际上,这些类型的视图大多是通过自定义视图完成的 用于自定义视图 但是您可以稍微作弊,在drawable文件夹中创建backgound.xml,然后粘贴代码: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="

我怎么做这个?它看起来不错,我想用这样的东西


顶部的线条应与标题的结尾相对应实际上,这些类型的视图大多是通过自定义视图完成的

用于自定义视图

但是您可以稍微作弊,在
drawable
文件夹中创建
backgound.xml
,然后粘贴代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle">

    <stroke android:color="@color/blue" android:width="4dp"/>
    <corners android:radius="10dp"/>
    <solid android:color="@color/white"/>
</shape>
然后你会得到下面的图片

注意

  • 我正在使用androidX
  • 您可以放置任何布局,而不是
    LinearLayout

1) 将项目迁移到
androidx

2) 在您的
build.gradle中包含依赖项

实现'com.google.android.material:material:1.0.0'

3) 在布局中使用:

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_height="wrap_content"
    android:hint="@string/hint_text">

  <com.google.android.material.textfield.TextInputEditText
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>

</com.google.android.material.textfield.TextInputLayout>

您需要使用材质组件主题

你能给我一张这样的图片吗@SumitShukla准备好了
<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_height="wrap_content"
    android:hint="@string/hint_text">

  <com.google.android.material.textfield.TextInputEditText
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>

</com.google.android.material.textfield.TextInputLayout>
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

</style>