Android background with a thin line

旧城冷巷雨未停 提交于 2019-12-12 03:51:57

问题


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?


回答1:


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"



回答2:


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:


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>


来源:https://stackoverflow.com/questions/16458694/android-background-with-a-thin-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!