Android background with a thin line

2019-08-27 15:49发布

I would like to create a background for my layouts.

What I used still now is:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <solid android:color="@android:color/darker_gray" />
    </shape>
</item>

<item android:bottom="5dp">
    <shape android:shape="rectangle">
        <solid android:color="@android:color/black" />
   </shape>
</item>
</layer-list>

It works nice untill the activity background were black... But now I would change my activity background. So not I would use a transparent background and draw a thin(5dp) darker_gray line at button.

Would somebody help me to create it by using items and shapes ... like this example shows?

3条回答
beautiful°
2楼-- · 2019-08-27 16:24

I found a good solution:

<item
    android:bottom="0dp"
    android:left="-6dp"
    android:right="-6dp"
    android:top="-6dp">

    <shape android:shape="rectangle" >

        <stroke
            android:width="5dp"
            android:color="@android:color/darker_gray" />

        <solid android:color="#00FFFFFF" />
    </shape>
</item>
查看更多
太酷不给撩
3楼-- · 2019-08-27 16:34

Try this this will display a thin black line at button of a LinearLayout having White background.

<?xml version="1.0" encoding="utf-8"?>
  <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <shape android:shape="rectangle" >
         <padding  android:bottom="1dp"/>
         <solid   android:color="#ff333333"/>

    </shape>
 </item>
 <item>
    <shape android:shape="rectangle" >
         <solid   android:color="#ffffffff"/>
    </shape>
</item>
</layer-list>
查看更多
祖国的老花朵
4楼-- · 2019-08-27 16:40

enter image description here

create style and apply it in android manifest file

<style name="Transparent" parent="android:Theme.Light">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:backgroundDimEnabled">false</item>
    </style>

    <color name="transparent">#00000000</color>

in manifest:

android:theme="@style/Transparent"
查看更多
登录 后发表回答