Ⅰ 怎麼自定義android標題欄修改TitleBar的布局
Android程序默認的Activity標題欄只能顯示一段文字,而且不能改變它的布局、顏色、標題欄的高度等。如果想要在標題欄加上個圖標、button、輸入框、進度條、修改標題欄顏色等,只能使用自定義的標題欄。自定義標題欄可以通過在onCreate函數中添加以下代碼來實現,需要注意的是代碼的順序必須按照下面的樣式,否則將無效。
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.mainactivity); //Activity的布局
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.titlebar); //標題欄的布局
雖然上面這樣可以在標題欄加入一些控制項,但是仍然不能改變標題欄的高度、背景色,要想達到這個目的,只能使用theme(主題)。因此往project里先添加一個style。改變背景色修改android:windowTitleBackgroundStyle的值,改變標題欄高度則修改android:windowTitleSize的值。下面是一個示例:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#778899</item>
</style>
<style name="activityTitlebar" parent="android:Theme">
<item name="android:windowTitleSize">32dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
接著再修改AndroidManifest.xml文件,找到要自定義標題欄的Activity,添加上android:theme值,比如:
Java代碼
<activity android:name=".MainActivity" android:theme="@style/activityTitlebar">
<activity android:name=".MainActivity" android:theme="@style/activityTitlebar">
android:theme值就是上面那個style.xml文件里定義的一個style的name值。
按照以上的步驟,修改標題欄布局、高度、背景色的功能就實現了。
Ⅱ 安卓手機app界面的標題欄,導航欄,標簽欄指的是什麼_
狀態欄:是指手機左上最頂上,顯示中國移動、安全衛士、電量、網速等等,在手機的頂部。下拉就會出現通知欄。
標題欄:是指一個APP程序最上部的titleBar,從名字就知道它顯然就是一個應用程序一個頁面的標題了,例如打開QQ消息主頁,最上面顯示消息那一欄就是標題欄。
導航欄:是手機最下面的返回,HOME,主頁三個鍵,有些是一個按鈕。
Ⅲ android 標題欄,狀態欄和導航欄的區別
就我理解,標題欄是手機左上最頂上,顯示中國移動,安全衛士,或者當前運行軟體的地方,手機的頂部。右邊顯示信號,電量,網速等等是狀態欄。
下拉就會出現通知欄。
至於導航欄是手機最下面的返回,HOME,主頁三個鍵,有些是一個按鈕。
Ⅳ android如何讓標題欄文字居中.不用自定義
可以先隱藏標題欄,在AndroidManifest里的對應的activity標簽里添加:android:theme="@android:style/Theme.Black.NoTitleBar"
然後在對應的layout布局裡添加一個TextView當做標題,設置文字居中
Ⅳ Android Studio中自定義標題欄的添加問題
mainifests中設置:
android:theme="@style/AppTheme"(即默認設置).
⒉values->styles.xml中設置:
style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar".
二values->styles.xml中:
在當先使用的style的parent屬性添加NoActionBar.如原先為
style name="AppTheme" parent="Theme.AppCompat.Light".
Ⅵ android 標題欄布局方式有哪些
原裝的Android標題欄配色比較單調,就是黑色的一坨,現在假設你的軟體需要獨自添加標題欄,這樣不僅美觀而且可以將進度條等加進去,如何實現:
方法一、
在你的那張Activity中onCreate方法中加上下面代碼:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main); //軟體activity的布局
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
//titlebar為自己標題欄的布局
但是新的問題又來了,這樣是無法深層的定製標題欄的,比如原有的高度和背景都沒有發生變化,那有沒有好的方法呢?答案是有的、
方法二:
因此先定義一個style,若修改背景請修改android:windowTitleBackgroundStyle
若修改標題欄高度,請修改android:windowTitleSize
例子:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomWindowTitleBackground">
<item name="android:background">#565656</item>
</style>
<style name="test" parent="android:Theme">
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
在程序的android_manifest.xml中對應activity中添加屬性android:theme = "@style/test" 就可以了
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.guardian"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" >
<activity android:name=".Test"
android:label="@string/app_name"
android:theme = "@style/test" //就在這里
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>
之後藉助於設置自定義的標題欄xml文件,就可以自定義標題欄布局了
Ⅶ android怎麼寫個自己的標題欄
我們做應用的時候經常想有自己的標題欄,在android平台示例:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title_1);
custom_title_1為自己定義的標題欄風格的xml文件索引。
當然僅僅這樣我們是去不掉系統的標題的,僅僅是在系統標題欄下面增加了一條自己的(客戶,註:android
UI系統是C/S模式)標題,怎麼用自己的標題欄覆蓋系統的呢?下面我們設計自己風格的標題。
兩種方式哦
1:
首先建立自己的styles.xml文件,如下:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the
"License");
you may not use this file except in compliance with the
License.
You may obtain a of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in
writing, software
distributed under the License is distributed on an "AS
IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied.
See the License for the specific language governing
permissions and
limitations under the License.
-->
<resources>
<!-- Base application theme is the default theme.
-->
<style name="Theme" parent="android:Theme">
</style>
<!-- Variation on our application theme that forces a
plain
text style. -->
<style name="Theme.PlainText">
<item
name="android:textAppearance">@style/TextAppearance.Theme.PlainText</item>
</style>
<!-- Variation on our application theme that has a
black
background. -->
<style name="Theme.Black">
<item
name="android:windowBackground">@drawable/screen_background_black</item>
</style>
<!-- A theme for a custom dialog appearance.
Here we use an ugly
custom frame. -->
<style name="Theme.CustomDialog"
parent="android:style/Theme.Dialog">
<item
name="android:windowBackground">@drawable/filled_box</item>
</style>
<!-- A theme that has a wallpaper background.
Here we explicitly specify
that this theme is to inherit from the
system's wallpaper theme,
which sets up various attributes
correctly. -->
<style name="Theme.Wallpaper"
parent="android:style/Theme.Wallpaper">
<item
name="android:colorForeground">#fff</item>
</style>
<!-- A theme that has a translucent background.
Here we explicitly specify
that this theme is to inherit from the
system's translucent theme,
which sets up various attributes
correctly. -->
<style name="Theme.Translucent"
parent="android:style/Theme.Translucent">
<item
name="android:windowBackground">@drawable/translucent_background</item><!--
@drawable/translucent_background -->
<item
name="android:windowNoTitle">true</item>
<item
name="android:colorForeground">#fff</item>
</style>
<!-- Variation on our application theme that has a
transparent
background; this example completely
removes the background,
allowing the activity to decide how to
composite. Also here we
force the translucency ourself rather
than making use of the built-in
translucent theme. -->
<style name="Theme.Transparent">
<item
name="android:windowIsTranslucent">true</item><!-- true -->
<item
name="android:windowAnimationStyle">@android:style/Animation.Translucent</item>
<item
name="android:windowBackground">@drawable/transparent_background</item>
<item
name="android:windowNoTitle">true</item>
<item
name="android:colorForeground">#fff</item>
</style><style name="TextAppearance.Theme.PlainText"
parent="android:TextAppearance.Theme">
<item
name="android:textStyle">normal</item>
</style>
<style name="ImageView120dpi">
<item
name="android:src">@drawable/stylogo120dpi</item>
<item
name="android:layout_width">wrap_content</item>
<item
name="android:layout_height">wrap_content</item>
</style>
<style name="ImageView160dpi">
<item
name="android:src">@drawable/stylogo160dpi</item>
<item
name="android:layout_width">wrap_content</item>
<item
name="android:layout_height">wrap_content</item>
</style>
<style name="ImageView240dpi">
<item
name="android:src">@drawable/stylogo240dpi</item>
<item
name="android:layout_width">wrap_content</item>
<item
name="android:layout_height">wrap_content</item>
</style>
<style
name="WindowTitleBackground_my">
<item
name="android:background">@drawable/title_bar</item>
</style>
<style
name="theme_mybackground">
<item
name="android:windowFullscreen">true</item>
<item
name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground_my</item>
</style>
</resources>
此文件是我從google給的示例代碼裡面拷貝出來的,紅色是為去掉系統標題欄新添加的,我們定義了自己標題欄的背景圖片(或者定義顏色也可),theme_mybackground
是覆蓋了系統風格,系統默認的android:windowFullscreen為false,修改系統默認的windowTitleBackGroundStyle為自己的風格Drawable,OK,下面比較關鍵的來了,在你的應用程序的Activity的超類裡面,在用super.onCreate(savedInstanceState);之前寫一句代碼如下:
setTheme(R.style.theme_mybackground);
super.onCreate(savedInstanceState);
//do something.
或者加入AndroidManifest.xml
OK,測試運行之
2:
直接在代碼裡面寫
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title_1);
custom_title_1為我們自己的標題欄風格,
測試運行之
轉載
Ⅷ android 怎麼設置標題欄大小
安卓app中的內置標題欄不同版本差異很大,但無論是2.3以下或4.0以上系統的標題欄,能自定義的屬性都很少。在開發Android應用中,想創建一個漂亮的自定義標題欄,有兩種方法,
第一,使用第三方框架,如SerlockActionbar。
第二,在XML中頭部做一個layout來作為標題欄(實際上就是普通的view)
我使用的是第二種方法,靈活性強些。
Ⅸ 如何修改android標題欄界面
方法一、在你的那張Activity中onCreate方法中加上下面代碼:
?
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main); //軟體activity的布局
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar); //titlebar為自己標題欄的布局
但是新的問題又來了,這樣是無法深層的定製標題欄的,比如原有的高度和背景都沒有發生變化,那有沒有好的方法呢?答案是有的、
方法二:
因此先定義一個style,若修改背景請修改android:windowTitleBackgroundStyle
若修改標題欄高度,請修改android:windowTitleSize
例子:
?
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="schemas.android.com/apk/res/android">
<style name="CustomWindowTitleBackground">
<item name="android:background">#565656</item>
</style>
<style name="test" parent="android:Theme">
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
在程序的android_manifest.xml中對應activity中添加屬性android:theme = "@style/test" 就可以了
?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="schemas.android.com/apk/res/android"
package="com.guardian"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" >
<activity android:name=".Test"
android:label="@string/app_name"
android:theme = "@style/test" //就在這里
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>
Ⅹ android的Activity控制項標題欄的屬性怎麼設置啊
Activity的標題欄,叫ActionBar,ActionBar位於Activity的頂部,可用來顯示activity的標題、Icon、Actions和一些用於交互的View。它也可被用於應用的導航。
ActionBar
標題欄常用屬性:
showAsAction屬性用來定義每個Action是如何顯示的
always表示永遠顯示在ActionBar中,如果屏幕空間不夠則無法顯示
ifRoom表示屏幕空間夠的情況下顯示在ActionBar中,不夠的話就顯示在overflow中
never則表示永遠顯示在overflow中