當前位置:首頁 » 安卓系統 » android自定義標題欄

android自定義標題欄

發布時間: 2022-08-10 03:30:37

A. Android自定義標題欄,如何使標題欄文字居中

設置ViewGroup為RelativeLayout,然後android:layout_centerInParent="true"

B. 怎麼自定義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值。

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

C. android自定義Theme,標題欄下出現一條藍線,如何去掉

用了下面這種布局之後解決了
<resources>

<style name="customTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/CustomActionBarStyle</item>
<item name="android:windowBackground">@color/background</item>
<item name="android:actionOverflowButtonStyle">@style/</item>
</style>

<style name="CustomActionBarStyle" parent="@android:style/Widget.ActionBar">

<!-- Change action bar background color -->
<item name="android:background">@color/background</item>
<item name="android:titleTextStyle">@style/CustomTitleTextStyle</item>
</style>

<style name="CustomTitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<!-- Change action bar title color -->
<item name="android:textColor">#ffffff</item>
</style>

<style name="" parent="@android:style/Widget.Holo.Light.ActionButton.Overflow">
<!-- Change overflow button background color -->
<item name="android:background">@color/background</item>
</style>

</resources>

D. 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為我們自己的標題欄風格,

測試運行之

轉載

E. android 怎麼設置標題欄大小

安卓app中的內置標題欄不同版本差異很大,但無論是2.3以下或4.0以上系統的標題欄,能自定義的屬性都很少。在開發Android應用中,想創建一個漂亮的自定義標題欄,有兩種方法,
第一,使用第三方框架,如SerlockActionbar。
第二,在XML中頭部做一個layout來作為標題欄(實際上就是普通的view)
我使用的是第二種方法,靈活性強些。

F. 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".

G. AndroidStudio自定義標題欄

什麼自定義標題欄,android的標簽欄,還是android studio本身的標題欄
android studio本身的應該改不了吧,android的話,那就是actionBar唄

熱點內容
我的世界ec伺服器怎麼獲得 發布:2024-03-29 21:21:44 瀏覽:708
小米4設置限制的訪問 發布:2024-03-29 21:21:10 瀏覽:405
linux向伺服器上傳文件 發布:2024-03-29 21:17:20 瀏覽:928
腳本健康cpu佔用率報警 發布:2024-03-29 21:16:42 瀏覽:254
vivox9什麼配置參數 發布:2024-03-29 21:08:09 瀏覽:936
傳奇計時器刷怪腳本 發布:2024-03-29 20:50:18 瀏覽:653
哇哇賺錢腳本 發布:2024-03-29 20:23:53 瀏覽:997
兩氣體壓縮 發布:2024-03-29 20:18:09 瀏覽:994
易語言教程解壓 發布:2024-03-29 20:18:00 瀏覽:786
我老爸的密碼是什麼 發布:2024-03-29 20:03:50 瀏覽:248