背景阴影

发布于 2025-02-08 04:48:51 字数 591 浏览 3 评论 0原文

Android中是否有任何方法可以应用落下阴影,如FIGMA或XD工具所示?

? > “在此处输入图像说明”

我有一个figma设计,我被困在创建此滴效果上,我有使用选择器layer-list尝试了它,

是否有任何方法可以应用 x,y和blur 以及带有不透明度的阴影颜色。

上面的属性仅适用于 deDittext ,但在下面不适合 textInputlayout

我的视图属性在下面。

Is there any way in Android that applies drop shadow as shown in Figma or XD Tool ?

enter image description here

I have got a figma design and I am stuck in creating this drop effect I have tried it using selector and layer-list

Is there any way to apply x , y and blur effect along with shadow color with opacity.

The above attributes only work for EditText but not working for TextInputLayout

My View Attribues in Figma are below .

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

凑诗 2025-02-15 04:48:51

新的和最佳的方法(我希望那是您需要的)

“在此处输入映像”

 <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/passwordTV"
        style="@style/Widget.App.TextInputLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@drawable/text_input_selector"
        android:backgroundTint="#0B102C"
        android:outlineAmbientShadowColor="#1EB0D5"
        android:outlineSpotShadowColor="#1EB0D5"
        android:textColorHint="#4A5478"
        android:translationZ="@dimen/_10sdp"
        app:endIconDrawable="@drawable/ic_show_password"
        app:endIconMode="password_toggle"
        app:hintTextColor="#4A5478">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/passwordEt"
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            android:drawableStart="@drawable/ic_lock"
            android:drawablePadding="7dp"
            android:hint="  Password"
            android:inputType="textPassword"
            android:textColor="@color/white"
            android:textColorHint="#CAD5F4"
            android:textSize="12dp" />

    </com.google.android.material.textfield.TextInputLayout>
  • 您只需在 drawsable 中创建一个text_input_selector

     &lt; selector xmlns:android =“ http://schemas.android.com/apk/res/android”&gt;
         &lt;项目
             android:state_focused =“ true”
             android:drawable =“@dr​​awable/backick_glow”/&gt;
     &lt;/selector&gt;
     

    text_input_selector.xml

  • 现在创建一个在 drawsable < /strong>


<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#0C263E"/>
    <corners android:radius="7dp"/>
</shape>

现在为背景发光创建 绘制 background_glow.xml

New and Best Approach (I hope that's what you required)

enter image description here

 <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/passwordTV"
        style="@style/Widget.App.TextInputLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@drawable/text_input_selector"
        android:backgroundTint="#0B102C"
        android:outlineAmbientShadowColor="#1EB0D5"
        android:outlineSpotShadowColor="#1EB0D5"
        android:textColorHint="#4A5478"
        android:translationZ="@dimen/_10sdp"
        app:endIconDrawable="@drawable/ic_show_password"
        app:endIconMode="password_toggle"
        app:hintTextColor="#4A5478">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/passwordEt"
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            android:drawableStart="@drawable/ic_lock"
            android:drawablePadding="7dp"
            android:hint="  Password"
            android:inputType="textPassword"
            android:textColor="@color/white"
            android:textColorHint="#CAD5F4"
            android:textSize="12dp" />

    </com.google.android.material.textfield.TextInputLayout>
  • you just create a text_input_selector in drawable

     <selector xmlns:android="http://schemas.android.com/apk/res/android">
         <item
             android:state_focused="true"
             android:drawable="@drawable/background_glow"/>
     </selector>
    

    text_input_selector.xml

  • Now create a shape for background glow in drawable

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#0C263E"/>
    <corners android:radius="7dp"/>
</shape>

background_glow.xml

风苍溪 2025-02-15 04:48:51

要设置文本小部件文本下面的文本的模糊阴影,您可以使用 Shadowcolor,Shadowdx,Shadowdy和Shadowradius TextView的属性。

  • shadowcolor 指定阴影的颜色。您可以在 rgb argb rrggbb aarrggbb 格式中指定颜色。
    shadowdx 指定阴影的水平偏移。它需要一个浮点值。

  • Shadowdy 指定阴影的垂直偏移。它需要一个浮点值。

  • Shadowradius 指定阴影的模糊半径。它需要一个浮点值。

     &lt; textView
     Android:ShadowColor =“#FF5722”
     Android:Shadowdx =“ 8”
     Android:Shadowdy =“ 8”
     Android:Shadowradius =“ 4”
     Android:text =“欢迎来到Kotlin Android教程。” /&gt;
     

  TextView textv = (TextView) findViewById(R.id.textview);
  textv.setShadowLayer(1, 0, 0, Color.BLACK)

To set a blurred shadow of text underneath the text in TextView widget, you can use shadowColor, shadowDx, shadowDy and shadowRadius attributes of TextView.

  • shadowColor specifies the color of shadow. You can specify color in rgb, argb, rrggbb, or aarrggbb formats.
    shadowDx specifies the horizontal offset of the shadow. It takes a float value.

  • shadowDy specifies the vertical offset of the shadow. It takes a float value.

  • shadowRadius specifies the blur radius of the shadow. It takes a float value.

     <TextView
     android:shadowColor="#FF5722"
     android:shadowDx="8"
     android:shadowDy="8"
     android:shadowRadius="4"
     android:text="Welcome to Kotlin Android Tutorial." />
    

or

  TextView textv = (TextView) findViewById(R.id.textview);
  textv.setShadowLayer(1, 0, 0, Color.BLACK)
故人的歌 2025-02-15 04:48:51

  • 您只需创建正常的角落可绘制的背景:

round_corner.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="2dp" android:color="#1EB0D5"/>
    <solid android:color="#0C263E"/>
    <corners android:radius="16dp"/>
</shape>
  • utlinespotshadowcoloroflineambientshadowcolor您将设置设置阴影颜色,然后您需要设置translationz vlaue使阴影显示
<com.google.android.material.textfield.TextInputLayout
        android:backgroundTint="@android:color/transparent"
        android:outlineAmbientShadowColor="#1EB0D5"
        android:outlineSpotShadowColor="#1EB0D5"
        android:translationZ="30dp"
        ...>

        <com.google.android.material.textfield.TextInputEditText
            android:background="@drawable/round_corner"
            ... />

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

enter image description here

  • you just create normal corner drawable background:

round_corner.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="2dp" android:color="#1EB0D5"/>
    <solid android:color="#0C263E"/>
    <corners android:radius="16dp"/>
</shape>
  • with the outlineSpotShadowColor and outlineAmbientShadowColor you going to set the shadow color, then you need to set translationZ a vlaue to make the shadow showen
<com.google.android.material.textfield.TextInputLayout
        android:backgroundTint="@android:color/transparent"
        android:outlineAmbientShadowColor="#1EB0D5"
        android:outlineSpotShadowColor="#1EB0D5"
        android:translationZ="30dp"
        ...>

        <com.google.android.material.textfield.TextInputEditText
            android:background="@drawable/round_corner"
            ... />

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

倾其所爱 2025-02-15 04:48:51

使用层列表的良好工作方法,只需根据需要更改纯色即可。

  <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        tools:ignore="MissingDefaultResource">
    
        <!-- Drop Shadow Stack -->
        <item>
            <shape>
                <padding
                    android:bottom="1.5dp"
                    android:left="1.5dp"
                    android:right="1.5dp"
                    android:top="1.5dp" />
    
                <solid android:color="#001E88E5" />
    
                <corners android:radius="@dimen/_8sdp" />
            </shape>
        </item>
        <item>
            <shape>
                <padding
                    android:bottom="1.5dp"
                    android:left="1.5dp"
                    android:right="1.5dp"
                    android:top="1.5dp" />
    
                <solid android:color="#051E88E5" />
    
                <corners android:radius="@dimen/_8sdp" />
            </shape>
        </item>
        <item>
            <shape>
                <padding
                    android:bottom="1.5dp"
                    android:left="1.5dp"
                    android:right="1.5dp"
                    android:top="1.5dp" />
    
                <solid android:color="#0A1E88E5" />
    
                <corners android:radius="@dimen/_8sdp" />
            </shape>
        </item>
        <item>
            <shape>
                <padding
                    android:bottom="1.5dp"
                    android:left="1.5dp"
                    android:right="1.5dp"
                    android:top="1.5dp" />
    
                <solid android:color="#0F1E88E5" />
    
                <corners android:radius="@dimen/_8sdp" />
            </shape>
        </item>
        <item>
            <shape>
                <padding
                    android:bottom="1.5dp"
                    android:left="1.5dp"
                    android:right="1.5dp"
                    android:top="1.5dp" />
    
                <solid android:color="#A61E88E5" />
    
                <corners android:radius="@dimen/_8sdp" />
            </shape>
        </item>
    
        <!-- Background -->
        <item android:id="@+id/itemShape">
            <shape>
                <gradient
                    android:angle="0"
                    android:endColor="@color/white"
                    android:startColor="@color/white" />
                <corners android:radius="@dimen/_8sdp" />
                <size android:width="90dp" android:height="90dp" />
            </shape>
        </item>
    
    </layer-list>
    

A good working approach to use Layer-list , Just Change solid color as required .

enter image description here

  <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        tools:ignore="MissingDefaultResource">
    
        <!-- Drop Shadow Stack -->
        <item>
            <shape>
                <padding
                    android:bottom="1.5dp"
                    android:left="1.5dp"
                    android:right="1.5dp"
                    android:top="1.5dp" />
    
                <solid android:color="#001E88E5" />
    
                <corners android:radius="@dimen/_8sdp" />
            </shape>
        </item>
        <item>
            <shape>
                <padding
                    android:bottom="1.5dp"
                    android:left="1.5dp"
                    android:right="1.5dp"
                    android:top="1.5dp" />
    
                <solid android:color="#051E88E5" />
    
                <corners android:radius="@dimen/_8sdp" />
            </shape>
        </item>
        <item>
            <shape>
                <padding
                    android:bottom="1.5dp"
                    android:left="1.5dp"
                    android:right="1.5dp"
                    android:top="1.5dp" />
    
                <solid android:color="#0A1E88E5" />
    
                <corners android:radius="@dimen/_8sdp" />
            </shape>
        </item>
        <item>
            <shape>
                <padding
                    android:bottom="1.5dp"
                    android:left="1.5dp"
                    android:right="1.5dp"
                    android:top="1.5dp" />
    
                <solid android:color="#0F1E88E5" />
    
                <corners android:radius="@dimen/_8sdp" />
            </shape>
        </item>
        <item>
            <shape>
                <padding
                    android:bottom="1.5dp"
                    android:left="1.5dp"
                    android:right="1.5dp"
                    android:top="1.5dp" />
    
                <solid android:color="#A61E88E5" />
    
                <corners android:radius="@dimen/_8sdp" />
            </shape>
        </item>
    
        <!-- Background -->
        <item android:id="@+id/itemShape">
            <shape>
                <gradient
                    android:angle="0"
                    android:endColor="@color/white"
                    android:startColor="@color/white" />
                <corners android:radius="@dimen/_8sdp" />
                <size android:width="90dp" android:height="90dp" />
            </shape>
        </item>
    
    </layer-list>
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文