【问题标题】:Android background with a thin line带有细线的 Android 背景
【发布时间】:2013-05-09 09:36:20
【问题描述】:

我想为我的布局创建一个背景。

我现在还在用的是:

<?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>

在活动背景变黑之前效果很好……但现在我要更改我的活动背景。所以我不会使用透明背景并在按钮处绘制一条细(5dp)darker_gray 线。

有人可以帮助我通过使用项目和形状来创建它......就像这个例子所示?

【问题讨论】:

  • 此时图像并不重要。所以我只需要在 LinearLayout 的按钮上画一条细线。
  • 好的,我会发布你想要的。

标签: android layout background shape


【解决方案1】:

我找到了一个很好的解决方案:

<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>

【讨论】:

    【解决方案2】:

    创建样式并将其应用到 android 清单文件中

    <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>
    

    在清单中:

    android:theme="@style/Transparent"
    

    【讨论】:

      【解决方案3】:

      试试这个,这将在具有白色背景的 LinearLayout 的按钮上显示一条细黑线。

      <?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>
      

      【讨论】:

      • @TAR515 只给底部填充。
      猜你喜欢
      • 2018-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-24
      • 1970-01-01
      • 1970-01-01
      • 2014-12-01
      • 2020-05-11
      相关资源
      最近更新 更多