【问题标题】:Android Button with No Padding无填充的 Android 按钮
【发布时间】:2013-01-01 03:53:39
【问题描述】:

我正在尝试使用开源的天线吊舱应用程序作为构建我的 android 应用程序的参考。我正在使用 ActionBarSherlock 并想在我的布局底部创建一个按钮,该按钮从一侧延伸到另一侧,没有填充。它应该是这样的:

我的 Styles.xml 如下所示:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="Theme.Application.Light" parent="@style/Theme.Sherlock.Light">
        <item name="attr/non_transparent_background">@color/white</item>
        <item name="attr/borderless_button">@drawable/borderless_button</item>   
    </style>

</resources>

borderless_button.xml 看起来像这样:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"><shape android:shape="rectangle">
        <solid android:color="@color/selection_background_color_light" />
        </shape></item>
    <item android:state_focused="true"><shape android:shape="rectangle">          
        <solid android:color="@color/selection_background_color_light" />
        </shape></item>
    <item><shape android:shape="rectangle">
        <solid android:color="@android:color/transparent" />
    </shape></item>
</selector>

attrs.xml 看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <attr name="borderless_button" format="reference" />
    <!-- Used in itemdescription -->
    <attr name="non_transparent_background" format="reference" />

</resources>

我的清单有这个:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Application.Light" >...</>

我的布局是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/footer"
        style="@android:style/ButtonBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/butConfirm"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Search" />

    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/queryString"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_margin="8dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:text="What would you like to search for?" />

        <EditText
            android:id="@+id/etxtQueryString"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/queryString"
            android:layout_margin="8dp"
            android:hint="Enter Query"
            android:inputType="textUri" />

    </RelativeLayout>

</RelativeLayout>

最终的样子:

我只需要一个按钮,但仍希望它覆盖整个屏幕宽度。

这是我用作指南的源代码的链接。 https://github.com/danieloeh/AntennaPod

任何帮助都会很棒!

谢谢

【问题讨论】:

  • 我在你的 XML 中看到了一些边距,你玩过这些数字吗?
  • 边距仅适用于 textview 和 edittext,它们不会影响按钮。

标签: android button actionbarsherlock android-styles


【解决方案1】:
<Button
        android:id="@+id/butConfirm"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Search"
        android:background="@null"/>

这应该可以解决问题!

【讨论】:

  • 这对我不起作用,因为我有一个可绘制的 xml 背景,只有一种颜色。
猜你喜欢
  • 2013-05-29
  • 2021-06-06
  • 2013-05-26
  • 2016-04-29
  • 2017-08-03
  • 2016-04-10
  • 2017-03-08
  • 1970-01-01
  • 2012-04-21
相关资源
最近更新 更多