導航:首頁 > 操作系統 > 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是什麼 瀏覽:59
皮帶壓縮機經常吸不上 瀏覽:201
西部隨行版怎樣加密 瀏覽:996
釘釘上如何壓縮圖片 瀏覽:924
cad輸入命令不顯示窗口 瀏覽:618
小米視頻加密之後怎麼看 瀏覽:76
超級程序員劉芳閱讀 瀏覽:832
顧家九爺在哪個app 瀏覽:820
我的世界怎麼在聯機大廳做伺服器 瀏覽:290
分手程序員 瀏覽:447
php將html導出為word 瀏覽:801
騰訊加密視頻能破解嗎 瀏覽:1007
反編譯後導入eclipse 瀏覽:948
買阿里雲伺服器有郵箱嗎 瀏覽:825
pdf卡片2004 瀏覽:309
e算量加密鎖檢測不到 瀏覽:777
python串口讀取數據類型 瀏覽:760
17年新款寶來壓縮機不跳 瀏覽:107
王者打著為什麼伺服器升級 瀏覽:847
aliyunlinux安裝 瀏覽:981