android - 如何在 TextView 周围设置阴影

标签 android textview shadow

<TextView
            android:id="@+id/text"
            android:layout_width="225dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_toRightOf="@+id/left"
            android:background="@anim/chatitemshaodow"
            android:fontFamily="calibri"
            android:padding="8dp"
            android:textColor="#636363"
            android:textSize="17dp" />

这是我的 TextView 控件,我想在 TextView 周围设置阴影。我可以在 TextView 中的文本上设置 Showdown,但无法在 TextView 上设置阴影。

我想在 android 中像给定屏幕一样设置 TextView 阴影。 enter image description here

最佳答案

创建一个新的可绘制资源文件。我将我的命名为 two_sided_border.xml。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is the line -->
<item>
    <shape>
        <solid android:color="@color/black" />
    </shape>
</item>
<!-- This is the main color -->
<item android:bottom="2dp" android:right="2dp">
    <shape>
        <solid android:color="@color/green" />
    </shape>
</item>
</layer-list>

然后将其用作 TextView 的背景。

<TextView
    android:id="@+id/t"
    android:background="@drawable/two_sided_border"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"/>

您的颜色和尺寸(填充、文字大小)可以调整以适应。

两个很棒的链接:

how to make stroke for 3 sides for a shape in android?

并从这里借用了一些代码:

Open-sided Android stroke?

ps Basil Miller 提供的另一个答案提供了为实际文本本身设置阴影的好方法。

textview

关于android - 如何在 TextView 周围设置阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28321003/

相关文章:

java - Android 编辑文本和对话框

c++ - 双抛物面阴影贴图

CSS淡出没有图像的水平规则/线条样式的div效果

android - WAIT_FOR_CONCURRENT_GC 阻塞是什么意思?

android - 无法解析符号 'REQUEST_ENABLE_BLUETOOTH'

android - iOS 或 Android 上的 WebKit 开发中的陷阱/错误

android - 创建不同颜色的删除线

java - 将数据对象检索到 ListView 时,Firebase 返回随机值

java - 构造函数 TextView() 未定义

android - React-Native 中带有实心阴影的文本