更改按钮的高度
我正在尝试更改我的应用中几个按钮的高度。更改按钮的高度
我已经尝试设置@android:color/transparent
作为android:background
,我也尝试了layout_height
设定值一样16dp
。
我怎么能给我的按钮更小的高度?
这里是风格的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>
设置按钮的高度,为wrap_content:
android:layout_height="wrap_content"
应该将按钮的高度设置为最小以显示其文本。
我已经将它设置为'wrap_content',并产生了上述结果:( – boz 2013-02-26 09:13:45
在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 website,它的基本设计,使Android开发人员轻松了许多,并像使用jQuery。
这看起来很有趣,但我真的刚刚开始与Android开发。这将是很好的学习如何做的事情没有任何额外的框架/图书馆 – boz 2013-02-26 09:37:14
这是公平的!只是抛出它,因为当我第一次来到Android时,我发现它有点混乱,祝你好运 – ComethTheNerd 2013-02-26 09:44:33
删除这个来自你的风采
<item name="android:height">20sp</item>
所以,如果你TextView
结束了
<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
android:height,这大概正好设置高度,使其忽略您的layout_height
。
你可以发布你的XML – Kirk 2013-02-25 18:04:16
@Kirk - 抱歉,完全忘了这么做。它现在在那里。 – boz 2013-02-26 09:14:19