Android開發(fā)之開關(guān)按鈕控件ToggleButton簡單用法示例
本文實(shí)例講述了Android開發(fā)之開關(guān)按鈕控件ToggleButton簡單用法。分享給大家供大家參考,具體如下:
先來看看運(yùn)行效果:
具體代碼如下:
res/layout/activity_main.xml文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ToggleButton android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textOff="橫向" android:textOn="縱向" android:checked="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="測試" /> </LinearLayout>
MainActivity.java文件:
package com.example.test03; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
Android如何動態(tài)改變App桌面圖標(biāo)
這篇文章主要介紹了 Android動態(tài)改變App桌面圖標(biāo)的方法,非常不錯,具有參考借鑒價(jià)值,需要的朋友參考下2017-01-01Android來電監(jiān)聽和去電監(jiān)聽實(shí)現(xiàn)代碼
本文是關(guān)于來點(diǎn)監(jiān)聽和去電監(jiān)聽展開問題,通過實(shí)例代碼講解,對android來電監(jiān)聽和去電監(jiān)聽的相關(guān)知識感興趣的朋友一起看看吧2017-06-06Android實(shí)現(xiàn)讀寫USB串口數(shù)據(jù)
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)讀寫USB串口數(shù)據(jù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-09-09Android實(shí)現(xiàn)讀取NFC卡卡號示例
本篇文章主要介紹了Android實(shí)現(xiàn)讀取NFC卡卡號示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-01-01Android通過Handler與AsyncTask兩種方式動態(tài)更新ListView(附源碼)
這篇文章主要介紹了Android通過Handler與AsyncTask兩種方式動態(tài)更新ListView的方法,結(jié)合實(shí)例形式分析了ListView動態(tài)更新的常用技巧,并附上完整實(shí)例源碼供讀者下載,需要的朋友可以參考下2015-12-12Android O實(shí)現(xiàn)Framework層CENTER鍵長按功能方法
這篇文章主要為大家介紹了Android O實(shí)現(xiàn)Framework層CENTER鍵長按功能方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08Flutter?Widget?之package?mason實(shí)現(xiàn)詳解
這篇文章主要為大家介紹了Flutter?Widget?之package:?mason實(shí)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11Android編程實(shí)現(xiàn)通話錄音功能的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)通話錄音功能的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android廣播接收機(jī)制實(shí)現(xiàn)錄音功能的操作技巧,需要的朋友可以參考下2017-06-06Android PhoneWindowManager監(jiān)聽屏幕右側(cè)向左滑動實(shí)現(xiàn)返回功能
這篇文章主要介紹了Android PhoneWindowManager監(jiān)聽屏幕右側(cè)向左滑動實(shí)現(xiàn)返回功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04