日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android 标题样式,Android定义各种样式的标题栏:requestWindowFeature()

發布時間:2025/3/11 Android 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 标题样式,Android定义各种样式的标题栏:requestWindowFeature() 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近在網上看到一篇介紹Android window的requestWindowFeature()的使用方法,共享出來大家學習學習

requestWindowFeature(Window.FEATURE_LEFT_ICON);

setContentView(R.layout.dialog_activity);

getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.drawable.ic_dialog_alert);

Android 應用程序窗體顯示狀態操作(requestWindowFeature()的應用)

我們在開發程序是經常會需要軟件全屏顯示、自定義標題(使用按鈕等控件)和其他的需求,今天這一講就是如何控制Android應用程序的窗體顯示.

首先介紹一個重要方法那就是requestWindowFeature(featrueId),它的功能是啟用窗體的擴展特性。參數是Window類中定義的常量。

一、枚舉常量

1.DEFAULT_FEATURES:系統默認狀態,一般不需要指定

2.FEATURE_CONTEXT_MENU:啟用ContextMenu,默認該項已啟用,一般無需指定

3.FEATURE_CUSTOM_TITLE:自定義標題。當需要自定義標題時必須指定。如:標題是一個按鈕時

4.FEATURE_INDETERMINATE_PROGRESS:不確定的進度

5.FEATURE_LEFT_ICON:標題欄左側的圖標

6.FEATURE_NO_TITLE:無標題

7.FEATURE_OPTIONS_PANEL:啟用“選項面板”功能,默認已啟用。

8.FEATURE_PROGRESS:進度指示器功能

9.FEATURE_RIGHT_ICON:標題欄右側的圖標

二、詳解1.默認顯示狀態

2.FEATURE_CUSTOM_TITLE詳解

this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(R.layout.main);

這是因為沒設置Featrue

在上面代碼后加:getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);

自定義標題完成,它是一個xml文件布局

title.xml

xmlversion="1.0"encoding="utf-8"?>

<<>LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<<>ImageViewandroid:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/icon"/>

<<>TextViewandroid:id="@+id/text"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:text="文本"/>

3.FEATURE_INDETERMINATE_PROGRESS詳解

表示一個進程正在運行

實現代碼

1.progress.xml

xmlversion="1.0"encoding="utf-8"?>

<<>LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<<>ProgressBarandroid:id="@+id/progress"

android:layout_width="wrap_content"android:layout_height="wrap_content"

android:layout_gravity="center_vertical"

style="?android:attr/progressBarStyleSmallTitle">

2.Java代碼

this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

setContentView(R.layout.main);

getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progress);

setProgressBarIndeterminateVisibility(true);this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

setContentView(R.layout.main);

getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progress);

setProgressBarIndeterminateVisibility(true);

4.FEATURE_LEFT_ICON詳解

左側顯示圖標

實現代碼

this.requestWindowFeature(Window.FEATURE_LEFT_ICON);

setContentView(R.layout.main);

getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon);this.requestWindowFeature(Window.FEATURE_LEFT_ICON);

setContentView(R.layout.main);

getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon);

5.FEATURE_NO_TITLE詳解

可用于全屏顯示

實現代碼

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.main);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);this.requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.main);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

雖然上面這樣可以在標題欄加入一些控件,但是仍然不能改變標題欄的高度、背景色,要想達到這個目的,只能使用theme(主題)。因此往project里先添加一個style。改變背景色修改android:windowTitleBackgroundStyle的值,改變標題欄高度則修改android:windowTitleSize的值。下面是一個示例:

xmlversion="1.0"encoding="utf-8"?>

#778899

32dp

@style/CustomWindowTitleBackground

接著再修改AndroidManifest.xml文件,找到要自定義標題欄的Activity,添加上android:theme值,比如:

android:theme值就是上面那個style.xml文件里定義的一個style的name值。按照以上的步驟,修改標題欄布局、高度、背景色的功能就實現了。xmlversion="1.0"encoding="utf-8"?>

<<>resources>

<<>stylename="CustomWindowTitleBackground">

<<>itemname="android:background">#778899

<<>stylename="activityTitlebar"parent="android:Theme">

<<>itemname="android:windowTitleSize">32dp

<<>itemname="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground

接著再修改AndroidManifest.xml文件,找到要自定義標題欄的Activity,添加上android:theme值,比如:

android:theme值就是上面那個style.xml文件里定義的一個style的name值。

按照以上的步驟,修改標題欄布局、高度、背景色的功能就實現了。

總結

以上是生活随笔為你收集整理的android 标题样式,Android定义各种样式的标题栏:requestWindowFeature()的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。