【问题标题】:How to add curved underline to an Edittext or a Searchview?如何为 Edittext 或 Searchview 添加曲线下划线?
【发布时间】:2017-03-17 23:13:03
【问题描述】:

如果可能,我想创建一个搜索视图或类似的编辑文本,我相信它是全息主题,但我的项目主题是 Appcompact,谢谢。

【问题讨论】:

  • 尝试使用自定义背景使用 xml drawable 进行编辑文本
  • 谢谢,但这是我的问题,我不知道该怎么做。
  • 参考here 了解如何制作带有圆角的editText
  • @rawa300 使用 xml drawable 然后使用 clip drawable
  • 谢谢大家,我相信这会成功的 :)

标签: android android-edittext android-custom-view android-theme searchview


【解决方案1】:

在你的布局文件中

<EditText
    android:id="@+id/editText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="EditText"
    android:padding="8dp"
    />

edit_text_drawable.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="16dp"/>
    <solid android:color="@android:color/transparent"/>
    <stroke
        android:color="@color/colorBlue"
        android:width="2dp" />
</shape>

这个drawable 将用作EditText 的背景。 标签 stroke 为这个形状创建轮廓 - 在此处设置轮廓宽度和颜色。

在您的代码中

EditText editText = (EditText) findViewById(R.id.editText);

ClipDrawable clipDrawable = new ClipDrawable
              (getResources().getDrawable(R.drawable.edit_text_drawable), 
                    Gravity.BOTTOM, ClipDrawable.VERTICAL);
clipDrawable.setLevel(2000);

editText.setBackground(clipDrawable);

此处 ClipDrawable “裁剪”背景可绘制对象。 ClipDrawable documentation

【讨论】:

  • 感谢分析器
猜你喜欢
  • 1970-01-01
  • 2013-03-31
  • 1970-01-01
  • 1970-01-01
  • 2012-12-08
  • 2013-02-21
  • 2016-08-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多