導航:首頁 > 操作系統 > Androidbutton的形狀

Androidbutton的形狀

發布時間:2022-08-25 05:11:59

android如何設置圓角按鈕

可以通過shape設置圓角
<!-- 設置圓角 -->
<corners android:radius="2dp" >
</corners>
擴展:
<?xml version="1.0" encoding="utf-8"?>
<!-- shape如果不聲明形狀默認是正方形 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 設置填充色 -->

<solid android:color="#4285f4" >
</solid>
<!-- 設置邊框的顏色和寬度 -->
<stroke
android:width="1dp"
android:color="#4285f4" >
</stroke>
</shape>
通過selector設置點擊效果

button_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- 這個是用於控制按鈕組背景的文件 -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<!-- **點擊時效果**********背景引用的資源*************************是否獲得焦點*********************是否按下******* -->
<item android:drawable="@drawable/button_p" android:state_focused="true" android:state_pressed="false"/>
<item android:drawable="@drawable/button_p" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@drawable/button_p" android:state_focused="false" android:state_pressed="true"/>

<!-- **************沒有任何操作時顯示的背景************** -->
<item android:drawable="@drawable/button_n"></item>
</selector>
在xml文件中設置button的background屬性。
android:background="@drawable/button_bg"

⑵ android 怎麼把button變成圓形

使用shape,請看下面截圖,例子來自於android學習手冊,360手機助手中下載,裡面有108個例子、源碼還有文檔。



<?xml version="1.0" encoding="utf-8"?>

<shape

xmlns:Android="http://schemas.android.com/apk/res/android"

android:shape="oval">

<!-- 填充的顏色 -->

<solid android:color="#FFFFFF"/>

<!-- 設置按鈕的四個角為弧形 -->

<!-- android:radius 弧形的半徑 -->

<corners android:radius="360dip"/>

<!-- padding: Button 裡面的文字與Button邊界的間隔 -->

<padding

android:left="10dp"

android:top="10dp"

android:right="10dp"

android:bottom="10dp"

/>

</shape>

-----Main layout文件

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/soft_info"

/>

<!—直接設置背景 -->

<Button

android:id="@+id/roundBtn1"

android:background="@drawable/btn_oval"

android:layout_width="50dip"

android:layout_height="50dip"

/>

<!— 調用shape自定義xml文件 -->

<Button

android:id="@+id/roundBtn"

android:text="橢圓按鈕"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/main_menu_btnshape"

/>

</LinearLayout>

----acitivity文件

public class MyLifeActivity extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

}

}

⑶ 在android中按鈕共分為幾種

從控制項來說分為2種:button(一般按鈕)和ImageButton(圖片按鈕);
但是大部分時候,開發者是可以通過各種方式自定義按鈕,這樣的話,界面呈現出來的按鈕是多種多樣的;
TextView,view等等,很多控制項其實都可以拿來當按鈕使用;
此外,還有包括ToggleButton,單選按鈕,多選按鈕等這些都屬於是功能比較專一的特殊按鈕了;
我想你只有對android比較了解的情況下,才可能理解深一些吧!

⑷ 怎樣利用photoshop製作android中的button按鈕形狀

工具:photoshop

步驟:

1、打開photoshop,在PS里「新建」一張圖片背景,顏色可以透明、也可以選擇其他前景色、背景色等;

⑸ 如何自定義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下


希望能幫到你,還望採納

閱讀全文

與Androidbutton的形狀相關的資料

熱點內容
蘋果app為什麼有的不可以左滑 瀏覽:813
php訪問access資料庫 瀏覽:416
愛情韓國三小時合集電影 瀏覽:824
華為的編譯器能編譯哪些語言 瀏覽:810
單片機如何實現電氣隔離 瀏覽:791
重生到建國初期賣軍火的小說 瀏覽:48
php微信接入 瀏覽:274
隱喻pdf 瀏覽:446
怎麼打開cuda編譯器 瀏覽:216
linux命令vmstat 瀏覽:568
vc編譯有錯誤 瀏覽:3
串口伺服器設置雲透傳 瀏覽:215
日本有劇情的電影 瀏覽:62
主角可以進入自己拍的影視世界小說 瀏覽:904
程序員那麼可愛陸漓簽協議 瀏覽:111
c計劃成龍電影 瀏覽:937
吃了人參到處搞的電影 瀏覽:883
javadefault編譯報錯 瀏覽:136
python子類繼承父類意義 瀏覽:637
男主汽車壞了女主被上了 瀏覽:535