Android Button with No Padding

孤街浪徒 提交于 2019-12-12 16:28:54

问题


I am trying to use the open source antennapod application as a reference for building my android application. I am using ActionBarSherlock and want to create a button at the bottom of my layout that extends from side to side with no padding. It should look like this:

My Styles.xml looks like this:

<?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 looks like this:

<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 looks like this:

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

My Manifest has this:

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

My layout is:

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

What it ends up looking like:

I just need one button but still want it to cover the whole width of the screen.

Here is the link to the source code I am using as a guide. https://github.com/danieloeh/AntennaPod

Any help would be awesome!

Thanks


回答1:


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

This should do the trick!



来源:https://stackoverflow.com/questions/13964748/android-button-with-no-padding

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