當前位置:首頁 » 安卓系統 » button屬性android

button屬性android

發布時間: 2022-05-07 22:20:23

① android button 樣式怎麼寫

如何自定義android Button樣式

android自帶的樣式比較難看,如何能夠自定義按鈕的樣式,使其顯示的跟美工設計的效果一樣,現與大家分享下

工具/原料

eclipse ADT

方法/步驟

在layout中添加2個按鈕,從下圖中可以看出在按鈕中調用了style和android:background屬性,這兩個屬性一個是自定義樣式,一個是給按鈕添加背景圖片,下面詳細介紹下

展開res目錄,可以看到在values目錄下有styles.xml文件,該文件用於自定義樣式,雙擊打開

下圖中標注的是我自定義的樣式,name為BtnStyle,當按鈕調用自定義樣式的時候訪問這個name

下圖是在button中調用自定義樣式的方法,比較簡單

下面分享下如何往按鈕中添加自定義圖片,使按鈕看起來更漂亮些,因不同手機解析度不同,那必然牽扯到圖片的拉伸,在android系統下有個很好的技術「九宮格「,可以對圖片進行處理,只對局部進行拉伸,給工具目錄存儲在android\sdk\tools\draw9patch.bat,經過該工具處理的圖片以.9.png結尾,放到drawable文件夾

下圖是在Button中通過android:background屬性載入圖片的方法,至此我們自定義的按鈕樣式也就完成了,當然這只是個引子,在具體的項目工程中實現的效果要比這個demo復雜很多,有好的設計思路歡迎交流。

出自:http://jingyan..com/article/454316ab4bdc66f7a7c03a13.html

② android里的BUTTON里的屬性問題

你這看上去很是矛盾啊。。。你把右和底去掉別寫。。你最下面那句是距離頂30dip..可是你上面的paddingTop為什麼寫成0啊。。具我實測。。這個padding 和margin 在某種意義上是一樣的效果。。

③ android 中button控制項都有些什麼常用的屬性

<Button
android:id="@+id/loginButton"
android:layout_width="50dp
android:layout_height="@dimen/button_footer_height"
android:layout_alignParentRight="true"
android:layout_gravity="center"
android:text="Login"
android:textSize="12dp"
android:visibility="invisible" />
我用到這些

④ android中怎樣給button中的字設置顏色

我們可以使用selector來實現Button的特效,如圖所示:

默認情況

獲得焦點的時候

點擊按鈕

main.xml

Xml代碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="按下或者獲得焦點Button會變不同顏色"
<SPAN style="COLOR: #ff0000">android:textColor="@color/button_text" </SPAN>/>
</LinearLayout>
www.2cto.com
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="按下或者獲得焦點Button會變不同顏色"
android:textColor="@color/button_text" />
</LinearLayout>

XML 文件保存在res/color/button_text.xml

Xml代碼
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:color="#ffff0000"/> <!-- pressed -->
<item android:state_focused="true" android:color="#ff0000ff"/> <!-- focused -->
<item android:color="#ff000000"/> <!-- default -->
</selector>

背景選擇器-selector

概述
在drawable/xxx.xml中配置,通過配置selector,可以使系統運行時根據控制項對象的狀態使用相應的圖片、文字等。
selector中的常用屬性
android:state_selected 控制項選中狀態,可以為true或false
android:state_focused 控制項獲得焦點狀態,可以為true或false
android:state_pressed 控制項點擊狀態,可以為true或false
android:state_enabled 控制項使能狀態,可以為true或false
android:state_checkable 控制項可勾選狀態,可以為true或false
android:state_checked 控制項勾選狀態,可以為true或false
注意:在狀態描述中,第一個匹配當前狀態的item會被使用。因此,如果第一個item沒有任何狀態特性的話,那麼它將每次都被使用,所以默認的值必須總是在最後。
android:window_focused 應用程序窗口焦點狀態,可以為true或false
android:color 定義特定狀態的顏色
#rgb
#argb
#rrggbb
#aarrggbb
為16進制顏色。這個顏色由rgb值指定,可帶alpha,必須以」#「開頭,後面跟隨alpha-red-green-blue信息,格式可以為:
使用selector設置背景
把下面的XML保存成.xml文件(比如list_item_bg.xml),運行時系統會根據ListView中列表項的狀態來使用相應的背景圖片。
drawable/list_item_bg.xml
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 默認時的背景圖片 -->
<item android:drawable="@drawable/pic1" />

<!-- 沒有焦點時的背景圖片 -->
<item android:state_window_focused="false"
android:drawable="@drawable/pic1" />

...

⑤ android 如何設置button的大小

在相對應的layout.xml文件中,button下可以定義android:layout_width和android:layout_height兩個屬性可以用來控制button的大小,希望可以幫助到你!

⑥ 設置 Button 的元素屬性 android:text 為 Exit 。

上面說「把Exit改成中文」的回答是正確的。

猜測是漢化時把「Exit」漢化成「退出」了。用原版應該不會有這個問題。

與此類似,後面讓添加一個按鈕把裡面的文字改成「Help」,也得寫「幫助」才能過去。

參考:網頁鏈接

⑦ 如何自定義android Button樣式

在windows7操作系統Android studio中按照如下方法定義button的樣式。

1、首先使用Android studio創建一個項目,項目結構如下:

⑧ android button怎麼用

千鋒扣丁學堂Android開發為您解答:
Button基本使用方法
首先,添加Button控制項到XML布局文件中。也可通過程序添加。
在布局文件中設置按鈕的一些屬性,如位置,寬高,按鈕上的字,顏色等。
比較重要的是要給按鈕一個id號,這是按鈕唯一的名字。
這樣在程序中可以通過如下形式獲得按鈕:
button = (Button)findViewById(R.id.buttonId);

處理按鈕點擊
按鈕點擊有兩種處理方法。
第一種是通過onClick屬性,通過這個屬性設置處理點擊事件的方法名,在Activity中實現這個方法。
另一種方法是典型的事件監聽機制的應用形式,下面詳細說明這兩種方法。

1.通過onClick屬性設置處理方法
在XML布局文件中設置Button的屬性:
android:onClick="yourMethodName"
然後在該布局文件對應的Acitivity中實現該方法:

/** Called when the user touches the button */

public void yourMethodName(View view)

{

// Do something in response to button click

}

需要注意的是這個方法必須符合三個條件:
1.public
2.返回void
3.只有一個參數View,這個View就是被點擊的這個控制項。

2.使用setOnClickListener添加監聽器對象

可以寫一個內部類,實現OnClickListener介面,在這個類中實現onClick方法,方法裡面寫在按鈕點擊時想做的具體工作。
將這個內部類的對象傳入按鈕的setOnClickListener方法中,即完成監聽器對象和按鈕的綁定(在事件源Button上注冊了事件監聽器),這時候只要按鈕被點擊,那麼監聽器對象的onClick方法就會被調用。
當然這里也不一定要自己寫一個內部類出來,比如這個例子:

Button button = (Button) findViewById(R.id.button_send);

button.setOnClickListener(new View.OnClickListener() {

public void onClick(View v)

{

// Do something in response to button click

}

});

⑨ 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.

熱點內容
電腦怎麼選擇配置 發布:2025-05-14 10:46:12 瀏覽:325
電腦怎麼不顯示手機連接伺服器失敗 發布:2025-05-14 10:42:28 瀏覽:9
安卓如何下載lv手游 發布:2025-05-14 10:35:45 瀏覽:383
pythondict添加key 發布:2025-05-14 10:33:59 瀏覽:382
柱子箍筋加密區長度 發布:2025-05-14 10:18:29 瀏覽:352
雲伺服器和內網穿透哪個好 發布:2025-05-14 10:16:41 瀏覽:627
安徽新能源網路配置是什麼 發布:2025-05-14 10:06:24 瀏覽:631
pinode搭建伺服器 發布:2025-05-14 10:04:23 瀏覽:4
電腦伺服器ip名稱 發布:2025-05-14 10:01:09 瀏覽:749
connectorpython 發布:2025-05-14 09:48:50 瀏覽:763