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實(shí)現(xiàn)多點(diǎn)觸控功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)多點(diǎn)觸控功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
Android 自定義驗(yàn)證碼輸入框的實(shí)例代碼(支持粘貼連續(xù)性)
這篇文章主要介紹了Android 自定義驗(yàn)證碼輸入框的實(shí)例代碼(支持粘貼連續(xù)性),代碼簡單易懂,非常不錯,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10
Android入門之Glide顯示網(wǎng)絡(luò)圖片高版本的使用詳解
這篇文章主要為大家詳細(xì)介紹了Android中Glide顯示網(wǎng)絡(luò)圖片高版本的使用方法,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起了解一下2023-02-02
在kotlin的安卓項(xiàng)目中使用dagger的操作方法
在 Kotlin 的 Android 項(xiàng)目中使用 ??Dagger??(特別是 ??Dagger Hilt??,官方推薦的簡化版)進(jìn)行依賴注入(DI)可以大幅提升代碼的可測試性和模塊化程度,這篇文章主要介紹了在kotlin的安卓項(xiàng)目中使用dagger的相關(guān)操作,需要的朋友可以參考下2025-04-04
Android 滑動返回Activity的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android 滑動返回Activity的實(shí)現(xiàn)代碼的相關(guān)資料,這里是訪微信滑動返回主頁的功能,需要的朋友可以參考下2017-07-07
Android 獲取屏幕高度,標(biāo)題高度,狀態(tài)欄高度(實(shí)例代碼)
getWindow().findViewById(Window.ID_ANDROID_CONTENT)這個方法獲取到的view就是程序不包括標(biāo)題欄的部分,然后就可以知道標(biāo)題欄的高度了2013-11-11

