1

我正在尝试更改我的应用程序中几个按钮的高度。

我的应用截图

我尝试设置@android:color/transparentandroid:background并且我也尝试将 a 设置layout_height16dp.

我怎样才能给我的按钮一个更小的高度?

这是样式xml:

<style name="Theme.PMBAppTheme.TextButton">
    <item name="android:textStyle">bold</item>
    <item name="android:textSize">14sp</item>
    <item name="android:textColor">@drawable/text_button_text</item>
    <item name="android:background">#ff3300</item>
    <item name="android:padding">0dp</item>
    <item name="android:height">20sp</item>
</style>

和布局:

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/register_btn_privacy"
        android:text="@string/privacy_policy" 
        style="@style/Theme.PMBAppTheme.TextButton"
        />

text_button_text

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_focused="true" android:state_pressed="true" android:color="@color/muted_pink_over" />
    <item android:state_focused="false" android:state_pressed="true" android:color="@color/muted_pink_over" /> 
    <item android:color="@color/muted_pink" /> 
</selector>
4

3 回答 3

4

将按钮的高度设置为 wrap_content:

android:layout_height="wrap_content"

这应该将按钮的高度设置为最小值以显示其文本。

于 2013-02-25T18:04:43.443 回答
1

Vapor API(我刚刚发布的一个 Android 的 jQuery 风格框架)中有一个可以使用的方法,叫做.size(int,int). View这会根据其所在容器的类型设置您的大小。所以像:

$.Button(R.id.register_btn_privacy).size(int width, int height);

很酷的是,您还可以链接调用来调整View. 例如:

$.Button(R.id.register_btn_privacy)
.size(50,100)    // set size
.text("Privacy Policy") // set the text
.bgColor(Color.RED)  // set the background color
.color(Color.WHITE);  // set the text color

如果您对Vapor API 网站感兴趣,请查看它,它基本上旨在使 Android 开发人员更容易并且喜欢使用 jQuery。

于 2013-02-26T09:27:27.637 回答
1

从你的风格中删除它

<item name="android:height">20sp</item>

所以你最终得到

<style name="Theme.PMBAppTheme.TextButton">
    <item name="android:textStyle">bold</item>
    <item name="android:textSize">14sp</item>
    <item name="android:textColor">@drawable/text_button_text</item>
    <item name="android:background">#ff3300</item>
    <item name="android:padding">0dp</item>
</style>

Button继承自TextView并根据TextView android:height,这可能是准确设置高度并导致它忽略您的layout_height.

于 2013-02-26T15:12:17.760 回答