如果可能的话,我想创建一个搜索 View 或一个类似的编辑文本,我相信它是全息主题,但我的项目主题是 Appcompact,thnx。
最佳答案
在你的布局文件中
<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>
此可绘制对象将用作 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
关于android - 如何向 Edittext 或 Searchview 添加弯曲的下划线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40417250/