Android 中的Theme和Style使用

2021-09-22 09:18:33 字數 3015 閱讀 2341

android 中的theme和style使用,還是比較簡單的。

1、 首先在res/values/styles.xml的resource中定義三個樣式,分別為:

然後在res/layout檔案下的activity_main.xml中的控制項中引用剛才定義的style。

android:id="@+id/textview1"

style="@style/textview"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/hello_world"/>

android:id="@+id/button1"

style="@style/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignleft="@+id/textview1"

android:layout_below="@+id/edittext1"

android:layout_margintop="18dp"

android:text="@string/hello_world"/>

android:id="@+id/edittext1"

style="@style/edittext"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignleft="@+id/button1"

android:layout_below="@+id/textview1"

android:layout_margintop="19dp"

android:ems="10"

android:text="@string/hello_world"/>

2、android的theme的使用

首先在res/values/themes.xml中定義theme。

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

然後在androidmanifest.xml中使用剛才定義的主題。

android:allowbackup="true"

android:icon="@drawable/ic_launcher"

android:label=

android:theme="@style/theme">

android:name="com.example.themedemo.mainactivity"

android:label=>

也可以用settheme(r.style.theme)來呼叫主題。效果圖就不上傳了。

Android中的主題 Theme

所以同樣是v7相容包,會有api版本號不同的區別,要注意。更多主題 以下都是指 包含 中來看就可以,提示有就有,沒有就沒有。black 黑色風格 light 光明風格 dark 黑暗風格 daynight 白晝風格 wall 牆紙為背景 translucent 透明背景 panel 平板風格 dia...

android自帶樣式 theme

theme.dialog 圖1 activity顯示為對話方塊模式 theme.notitlebar 圖2 不顯示應用程式標題欄 theme.notitlebar.fullscreen 圖3 不顯示應用程式標題欄,並全屏 theme.light 圖4 背景為白色 theme.light.notitl...

Android開發應用之Theme和Style

方便地定義顯示效果,不用每次定義元件時重複定義屬性值,在android系統中引入了主題theme和樣式style的概念。theme是針對窗體級別的,而style是針對元件級別的,他們都可以通過style.xml資源檔案進行設定。主題和樣式都可以通過繼承實現重用。theme和style資源都存放在re...