我需要让我的EditText看起来像它的深度,如下图所示。
我有这种形状,我不知道要添加什么
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="50dp" />
<solid android:color="@color/primary_dark" />
</shape>
答案 0 :(得分:8)
你可以用这样的drawable
来实现这个目标:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--background to compensate the transparency under shadow and glow (for bigger depth values)-->
<item>
<shape android:shape="rectangle">
<corners android:radius="50dp" />
<solid android:color="@color/primary_dark" />
</shape>
</item>
<!--top, dark, inner shadow-->
<item
android:bottom="@dimen/depth">
<shape android:shape="rectangle">
<corners android:radius="50dp" />
<solid android:color="#1A000000" />
</shape>
</item>
<!--bottom, light, outer glow-->
<item
android:top="@dimen/depth">
<shape android:shape="rectangle">
<corners android:radius="50dp" />
<solid android:color="#4DFFFFFF" />
</shape>
</item>
<!--your color-->
<item
android:top="@dimen/depth"
android:bottom="@dimen/depth">
<shape android:shape="rectangle">
<corners android:radius="50dp" />
<solid android:color="@color/primary_dark />
</shape>
</item>
</layer-list>
并在dimen
dimens.xml
<dimen name="depth">2dp</dimen>
通过更改dimen
,您可以更改drawable
答案 1 :(得分:3)
这也可能使你的场看起来接近效果,但有一点深度(见下文)。可能值得将背景添加到外部视图以包装编辑文本,以便在您尚未完成此操作时缩进文本。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- outer shine -->
<item
android:top="4dp"
android:left="4dp">
<shape android:shape="rectangle">
<corners android:radius="50dp" />
<solid android:color="#1597FB" />
</shape>
</item>
<!-- inner shadow -->
<item>
<shape android:shape="rectangle">
<corners android:radius="50dp" />
<solid android:color="#004173" />
</shape>
</item>
<!-- inner background -->
<item
android:top="2dp"
android:left="2dp">
<shape android:shape="rectangle">
<corners android:radius="50dp" />
<solid android:color="#006EC3" />
</shape>
</item>
</layer-list>
然后你按照下面的EditText;
<FrameLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:background="@drawable/rounded_rect_layered_combined">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:textColor="#ffffff"/>
</FrameLayout>