當前位置:首頁 » 安卓系統 » 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",就可以了!

熱點內容
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 瀏覽:737
wifi密碼設置什麼好 發布:2025-05-12 14:49:17 瀏覽:150
三位數乘兩位數速演算法 發布:2025-05-12 13:05:48 瀏覽:399
暴風影音緩存在哪裡 發布:2025-05-12 12:42:03 瀏覽:545
access資料庫exe 發布:2025-05-12 12:39:04 瀏覽:632
五開的配置是什麼 發布:2025-05-12 12:36:37 瀏覽:367