編輯:關於 Android 程式設計
開發時常需要快速切換 Activity 的外觀風格,而這些多半只要一行 android:theme 就能搞定。以下把平台內建的樣式整理成對照清單,寫在清單檔的 <activity> 節點上即可。
// 把 Activity 變成對話框外觀 android:theme="@android:style/Theme.Dialog" // 隱藏標題列 android:theme="@android:style/Theme.NoTitleBar" // 隱藏標題列並全螢幕 android:theme="@android:style/Theme.NoTitleBar.Fullscreen" // 白色背景 android:theme="@android:style/Theme.Light" // 白色背景、無標題列 android:theme="@android:style/Theme.Light.NoTitleBar" // 白色背景、無標題列、全螢幕 android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" // 黑色背景 android:theme="@android:style/Theme.Black" // 黑色背景、無標題列 android:theme="@android:style/Theme.Black.NoTitleBar" // 黑色背景、無標題列、全螢幕 android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" // 以系統桌布作為應用背景 android:theme="@android:style/Theme.Wallpaper" // 系統桌布背景、無標題列 android:theme="@android:style/Theme.Wallpaper.NoTitleBar" // 系統桌布背景、無標題列、全螢幕 android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen" // 半透明效果 android:theme="@android:style/Theme.Translucent" // 半透明、無標題列 android:theme="@android:style/Theme.Translucent.NoTitleBar" // 半透明、無標題列、全螢幕 android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
用法示例:
<activity
android:name=".SplashActivity"
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" />
從 Android 5.0 起 Material Design 成為預設,Theme.Light 這類舊樣式雖仍可用,但建議改用 Theme.AppCompat.Light.NoActionBar 等 AppCompat 版本,才能在各版本上維持一致的外觀並正確套用 ActionBar 與 Material 元件。
Android 網路開發:抓取線上 XML 並用 ListView 呈現
上次我們示範了如何從網路取得一張圖片,這次換成抓取文字檔,並以實際開發中最常見的 XML 為例。 範例的 XML 內容如下: <?xml version=1.0
布局與控件(四):Button 的兩種事件綁定方式與自訂背景
第 4 節 Button Button 是使用者互動的起點,也是每個 Android 新手都會碰到的第一個「會動」的控件。 從繼承結構看,Button 直接繼承自
MPAndroidChart 使用技巧:折線圖與樣式封裝
前言 由於之前項目中用到圖表的次數不少,若全靠手繪不僅費時,效果也未必達標。網上關於圖表的開源「輪子」很豐富,於是決定找一個來熟練運用,方便以後隨取隨用。 在 GitHu
自定義 View 打造垂直跑馬燈:完整思路與程式碼解析
先看效果: 畫面中間的色塊是影片轉 GIF 造成的失真,可以忽略。 大家都熟悉,水平方向的跑馬燈用 Android 原生的 TextView 加上跑馬燈屬性就能搞定;但