当前位置:首页 » 安卓系统 » androidbutton属性

androidbutton属性

发布时间: 2023-03-12 04:54:30

A. Android RadioButton控件怎么设置图片(属性)android:(drawable)

我觉得RadioButton原始的button如果设置为 android:button="@null“ 而用android:drowableLeft=”@drawable/radiobtn_selector“;这样显示图片的话效果会更加好,而且可以用android:drawablePading=”10dp“这个属性控制图片和字儿的距离。 希望可以帮到你。Thanks

B. 如何自定义android Button样式

在windows7操作系统Android studio中按照如下方法定义button的样式。

1、首先使用Android studio创建一个项目,项目结构如下:

C. android 如何设置button的大小

在相对应的layout.xml文件中,button下可以定义android:layout_width和android:layout_height两个属性可以用来控制button的大小,希望可以帮助到你!

D. android中button有几种状态

Android中,button按钮通常有三个状态:

1. normal(正常状态);
2. focus(焦点状态);
3. pressed(按下状态)
4. selected(选中状态)

注意:按下后未松开前是pressed,表示按下。
松开后当前项目获得焦点,是focused。
focused的项只有一个,selected是当选中该按钮时显示的状态

E. android button 的全部属性 谢谢

看文档啊
继承自 VIEW VIEW 有的属性它都能用
XML Attributes
Attribute Name Related Method Description
android:autoLink setAutoLinkMask(int) Controls whether links such as urls and email addresses are automatically found and converted to clickable links.
android:autoText setKeyListener(KeyListener) If set, specifies that this TextView has a textual input method and automatically corrects some common spelling errors.
android:bufferType setText(CharSequence,TextView.BufferType) Determines the minimum type that getText() will return.
android:capitalize setKeyListener(KeyListener) If set, specifies that this TextView has a textual input method and should automatically capitalize what the user types.
android:cursorVisible setCursorVisible(boolean) Makes the cursor visible (the default) or invisible.
android:digits setKeyListener(KeyListener) If set, specifies that this TextView has a numeric input method and that these specific characters are the ones that it will accept.
android:drawableBottom (int,int,int,int) The drawable to be drawn below the text.
android:drawableLeft (int,int,int,int) The drawable to be drawn to the left of the text.
android:drawablePadding setCompoundDrawablePadding(int) The padding between the drawables and the text.
android:drawableRight (int,int,int,int) The drawable to be drawn to the right of the text.
android:drawableTop (int,int,int,int) The drawable to be drawn above the text.
android:editable If set, specifies that this TextView has an input method.
android:editorExtras setInputExtras(int) Reference to an <input-extras> XML resource containing additional data to supply to an input method, which is private to the implementation of the input method.
android:ellipsize setEllipsize(TextUtils.TruncateAt) If set, causes words that are longer than the view is wide to be ellipsized instead of broken in the middle.
android:ems setEms(int) Makes the TextView be exactly this many ems wide.
android:freezesText setFreezesText(boolean) If set, the text view will include its current complete text inside of its frozen icicle in addition to meta-data such as the current cursor position.
android:gravity setGravity(int) Specifies how to align the text by the view's x- and/or y-axis when the text is smaller than the view.
android:height setHeight(int) Makes the TextView be exactly this many pixels tall.
android:hint setHint(int) Hint text to display when the text is empty.
android:imeActionId setImeActionLabel(CharSequence,int) Supply a value for EditorInfo.actionId used when an input method is connected to the text view.
android:imeActionLabel setImeActionLabel(CharSequence,int) Supply a value for EditorInfo.actionLabel used when an input method is connected to the text view.
android:imeOptions setImeOptions(int) Additional features you can enable in an IME associated with an editor to improve the integration with your application.
android:includeFontPadding setIncludeFontPadding(boolean) Leave enough room for ascenders and descenders instead of using the font ascent and descent strictly.
android:inputMethod setKeyListener(KeyListener) If set, specifies that this TextView should use the specified input method (specified by fully-qualified class name).
android:inputType setRawInputType(int) The type of data being placed in a text field, used to help an input method decide how to let the user enter text.
android:lineSpacingExtra setLineSpacing(float,float) Extra spacing between lines of text.
android:lineSpacingMultiplier setLineSpacing(float,float) Extra spacing between lines of text, as a multiplier.
android:lines setLines(int) Makes the TextView be exactly this many lines tall.
android:linksClickable setLinksClickable(boolean) If set to false, keeps the movement method from being set to the link movement method even if autoLink causes links to be found.
android:marqueeRepeatLimit setMarqueeRepeatLimit(int) The number of times to repeat the marquee animation.
android:maxEms setMaxEms(int) Makes the TextView be at most this many ems wide.
android:maxHeight setMaxHeight(int) Makes the TextView be at most this many pixels tall.
android:maxLength setFilters(InputFilter) Set an input filter to constrain the text length to the specified number.
android:maxLines setMaxLines(int) Makes the TextView be at most this many lines tall.
android:maxWidth setMaxWidth(int) Makes the TextView be at most this many pixels wide.
android:minEms setMinEms(int) Makes the TextView be at least this many ems wide.
android:minHeight setMinHeight(int) Makes the TextView be at least this many pixels tall.
android:minLines setMinLines(int) Makes the TextView be at least this many lines tall.
android:minWidth setMinWidth(int) Makes the TextView be at least this many pixels wide.
android:numeric setKeyListener(KeyListener) If set, specifies that this TextView has a numeric input method.
android:password setTransformationMethod(TransformationMethod) Whether the characters of the field are displayed as password dots instead of themselves.
android:phoneNumber setKeyListener(KeyListener) If set, specifies that this TextView has a phone number input method.
android:privateImeOptions setPrivateImeOptions(String) An addition content type description to supply to the input method attached to the text view, which is private to the implementation of the input method.
android:scrollHorizontally setHorizontallyScrolling(boolean) Whether the text is allowed to be wider than the view (and therefore can be scrolled horizontally).
android:selectAllOnFocus setSelectAllOnFocus(boolean) If the text is selectable, select it all when the view takes focus instead of moving the cursor to the start or end.
android:shadowColor setShadowLayer(float,float,float,int) Place a shadow of the specified color behind the text.
android:shadowDx setShadowLayer(float,float,float,int) Horizontal offset of the shadow.
android:shadowDy setShadowLayer(float,float,float,int) Vertical offset of the shadow.
android:shadowRadius setShadowLayer(float,float,float,int) Radius of the shadow.
android:singleLine setTransformationMethod(TransformationMethod) Constrains the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines, and advances focus instead of inserting a newline when you press the enter key.
android:text setText(CharSequence,TextView.BufferType) Text to display.
android:textAppearance Base text color, typeface, size, and style.
android:textColor setTextColor(int) Text color.
android:textColorHighlight setHighlightColor(int) Color of the text selection highlight.
android:textColorHint setHintTextColor(int) Color of the hint text.
android:textColorLink setLinkTextColor(int) Text color for links.
android:textIsSelectable isTextSelectable() Indicates that the content of a non-editable text can be selected.
android:textScaleX setTextScaleX(float) Sets the horizontal scaling factor for the text.
android:textSize setTextSize(int,float) Size of the text.
android:textStyle setTypeface(Typeface) Style (bold, italic, bolditalic) for the text.
android:typeface setTypeface(Typeface) Typeface (normal, sans, serif, monospace) for the text.
android:width setWidth(int) Makes the TextView be exactly this many pixels wide.

F. android 的Button怎样自动触发按下的动作

android 的Button自动触发按下的动作需要在Button添加android:onClick="click"属性,click为方法名,使用步骤如下:

1、使用Android studio创建一个Android项目并打开布局文件,在布局文件中添加一个Button,并设置android:onClick="click",如下图:

G. 如何自定义android Button样式

亲,可以用到Drawable中的shape哦,给你一个demo

java"><?xmlversion="1.0"encoding="utf-8"?>
<selectorxmlns:android="

<itemandroid:state_focused="false">
<shape>
<solidandroid:color="@color/find_passwordbar_bg"/>
<strokeandroid:width="0.5dp"android:color="#C8C8C8"/>
</shape>
</item>

<itemandroid:state_focused="true">
<shape>
<solidandroid:color="@color/find_passwordbar_bg"/>
<strokeandroid:width="0.5dp"android:color="@color/main_color"/>
</shape>
</item>

</selector>

各个属性的介绍

solid:实心,就是填充的意思
android:color指定填充的颜色

gradient:渐变
android:startColor和android:endColor分别为起始和结束颜色,ndroid:angle是渐变角度,必须为45的整数倍。
另外渐变默认的模式为android:type="linear",即线性渐变,可以指定渐变为径向渐变,android:type="radial",径向渐变需要指定半径android:gradientRadius="50"。

stroke:描边
android:width="2dp"描边的宽度,android:color描边的颜色。
我们还可以把描边弄成虚线的形式,设置方式为:
android:dashWidth="5dp"
android:dashGap="3dp"
其中android:dashWidth表示'-'这样一个横线的宽度,android:dashGap表示之间隔开的距离。

corners:圆角
android:radius为角的弧度,值越大角越圆。
我们还可以把四个角设定成不同的角度,方法为:
<corners
android:topRightRadius="20dp"右上角
android:bottomLeftRadius="20dp"右下角
android:topLeftRadius="1dp"左上角
android:bottomRightRadius="0dp"左下角
/>

我自己写的一个按钮,效果就像图中所示,用的Shape



新建后存放位置在res/drawable下


希望能帮到你,还望采纳

H. android按钮隐藏属性

设置android:visibility="gone"

在Android开发中,大部分控件都有visibility这个属性,其属性有3个分别为“visible ”、“invisible”、“gone”。主要用来设置控制控件的显示和隐藏。
visible :可见
invisible:不可见,但是当前view占位(即显示空白)
gone:不可见(隐藏,不显示空白)

I. 求 android RadioButton属性详解

一: 单选按钮RadioButton在Android平台上也应用的非常多,比如一些选择项的时候,会用到单选按钮,实现单选按钮由两部分组成,也就是RadioButton和RadioGroup配合使用

RadioButton的单选按钮;

RadioGroup是单选组合框,用于将RadioButton框起来;

在没有RadioGroup的情况下,RadioButton可以全部都选中;

当多个RadioButton被RadioGroup包含的情况下,RadioButton只可以选择一个;

注意:单选按钮的事件监听用setOnCheckedChangeListener来对单选按钮进行监听

例子:一道选择题,选择哪个城市美女最多,当然,这个就是为了测试

Java代码
1.package org.loulijun.radio;
2.
3.import android.app.Activity;
4.import android.os.Bundle;
5.import android.view.Gravity;
6.import android.widget.RadioButton;
7.import android.widget.RadioGroup;
8.import android.widget.TextView;
9.import android.widget.Toast;
10.
11.public class RadioTest extends Activity {
12. /** Called when the activity is first created. */
13. TextView textview;
14. RadioGroup radiogroup;
15. RadioButton radio1,radio2,radio3,radio4;
16. @Override
17. public void onCreate(Bundle savedInstanceState) {
18. super.onCreate(savedInstanceState);
19. setContentView(R.layout.main);
20. textview=(TextView)findViewById(R.id.textview1);
21. radiogroup=(RadioGroup)findViewById(R.id.radiogroup1);
22. radio1=(RadioButton)findViewById(R.id.radiobutton1);
23. radio2=(RadioButton)findViewById(R.id.radiobutton2);
24. radio3=(RadioButton)findViewById(R.id.radiobutton3);
25. radio4=(RadioButton)findViewById(R.id.radiobutton4);
26.
27. radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
28.
29. @Override
30. public void onCheckedChanged(RadioGroup group, int checkedId) {
31. // TODO Auto-generated method stub
32. if(checkedId==radio2.getId())
33. {
34. DisplayToast("正确答案:"+radio2.getText()+",恭喜你,回答正确!");
35. }else
36. {
37. DisplayToast("请注意,回答错误!");
38. }
39. }
40. });
41. }
42. public void DisplayToast(String str)
43. {
44. Toast toast=Toast.makeText(this, str, Toast.LENGTH_LONG);
45. toast.setGravity(Gravity.TOP,0,220);
46. toast.show();
47. }
48.}

strings.xml文件

Xml代码
1.<?xml version="1.0" encoding="utf-8"?>
2.<resources>
3. <string name="hello">哪个城市美女多?</string>
4. <string name="app_name">单选按钮测试</string>
5. <string name="radiobutton1">杭州</string>
6. <string name="radiobutton2">成都</string>
7. <string name="radiobutton3">重庆</string>
8. <string name="radiobutton4">苏州</string>
9.</resources>

main.xml文件:注意,这里面,4个RadioButton包含在RadioGroup中

Xml代码
1.<?xml version="1.0" encoding="utf-8"?>
2.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3. android:orientation="vertical"
4. android:layout_width="fill_parent"
5. android:layout_height="fill_parent"
6. >
7.<TextView
8. android:layout_width="fill_parent"
9. android:layout_height="wrap_content"
10. android:text="@string/hello"
11. android:id="@+id/textview1"
12. />
13. <RadioGroup
14. android:id="@+id/radiogroup1"
15. android:layout_width="wrap_content"
16. android:layout_height="wrap_content"
17. android:orientation="vertical"
18. android:layout_x="3px"
19. >
20. <RadioButton
21. android:id="@+id/radiobutton1"
22. android:layout_width="wrap_content"
23. android:layout_height="wrap_content"
24. android:text="@string/radiobutton1"
25. />
26. <RadioButton
27. android:id="@+id/radiobutton2"
28. android:layout_width="wrap_content"
29. android:layout_height="wrap_content"
30. android:text="@string/radiobutton2"
31. />
32. <RadioButton
33. android:id="@+id/radiobutton3"
34. android:layout_width="wrap_content"
35. android:layout_height="wrap_content"
36. android:text="@string/radiobutton3"
37. />
38. <RadioButton
39. android:id="@+id/radiobutton4"
40. android:layout_width="wrap_content"
41. android:layout_height="wrap_content"
42. android:text="@string/radiobutton4"
43. />
44. </RadioGroup>
45.</LinearLayout>

二:Android 自定义RadioButton的样式(和上面关系不大)

我们知道Android控件里的button,listview可以用xml的样式自定义成自己希望的漂亮样式。

最近用到RadioButton,利用xml修改android:background="@drawable/button_drawable",其中button_drawable为自己定义的.xml文件(res/drawable文件下),但是不成功,到网上查找,也没有正确的说法,我就开始自己尝试,最后做好了。

其实方法很简单,同样在res/drawable新建radiobutton.xml如下

Xml代码
1.<selector xmlns:android="http://schemas.android.com/apk/res/android">
2.
3. <item
4.
5.
6. android:state_enabled="true"
7.
8. android:state_checked="true"
9.
10. android:drawable="@drawable/check" />
11.
12. <item
13.
14. android:state_enabled="true"
15.
16. android:state_checked="false"
17.
18. android:drawable="@drawable/checknull" />
19.
20. </selector>
check和checknull分别为选中和位选中的图片。
然后在你的布局文件中,RadioButton 布局
设置android:button = "@drawable/radiobutton",就可以了!

热点内容
原神怎么看服务器版本 发布:2025-05-13 17:09:14 浏览:73
java连接符 发布:2025-05-13 17:05:44 浏览:57
hadoop删除文件夹 发布:2025-05-13 17:00:14 浏览:509
sql数据库远程备份 发布:2025-05-13 16:48:13 浏览:528
app什么情况下找不到服务器 发布:2025-05-12 15:46:25 浏览:714
php跳过if 发布:2025-05-12 15:34:29 浏览:467
不定时算法 发布:2025-05-12 15:30:16 浏览:131
c语言延时1ms程序 发布:2025-05-12 15:01:30 浏览:167
动物园灵长类动物配置什么植物 发布:2025-05-12 14:49:59 浏览:740
wifi密码设置什么好 发布:2025-05-12 14:49:17 浏览:150