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

android自定義標題

發布時間: 2022-05-15 03:28:06

㈠ android 怎麼設置標題欄大小

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

㈡ 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 怎樣動態改變Activity的標題

1、改變標題內容:public void setTitle (CharSequence title)
2、隱藏標題:requestWindowFeature(Window.FEATURE_NO_TITLE);

3、隱藏標題和最上面的電池電量及信號欄(全屏):

(請發郵件到[email protected]獲得翻強軟體。)

java">publicvoidsetFullscreen(){
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

4、自定義標題內容
1)

manifast.xml文件中MainActivity的聲明:
<activity
android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:label="@string/titlebar_text"
</actibity>

2)MainActivity文件中:

1.requestWindowFeature(Window.FEATURE_NO_TITLE);//設置窗口無標題欄
2.setContentView(R.layout.main);
3.//動態設置標題的值,getTitle()的值是該activity的聲明中android:label的值
4.((TextView)findViewById(R.id.titlebar_text)).setText(getTitle());

其中,getTitle()取得的值就是上述android:label="@string/titlebar_text"的值

5、自定義標題布局

protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
//預先設置允許改變的窗口狀態,需在setContentView之前調用,否則設置標題時拋運行時錯誤。
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.custom_title);
//標題區域可設置為layout,如此可以有豐富的展現方式
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title_1);
}

reslayoutcustom_title_1.xml(比如http://www.tiecou.com/)包含一個TextView 用於顯示標題。Android可以把標題做為一個layout來展示,具有很好的擴展性。

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/screen"

android:layout_width="fill_parent"android:layout_height="fill_parent"

android:orientation="vertical">

<TextViewandroid:id="@+id/left_text"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:text="@string/custom_title_left"/>
</RelativeLayout>

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

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

㈤ android自定義Intent選擇界面的標題

可以使用
Intent.createChooser()
的方法來創建
Intent,並傳入想要的
Sting
作為標題。
以wallpaper
選擇框為例,當在Launcher
workspace的空白區域上長按,會彈出wallpaper的選擇框,選擇框的標題為”Choose
wallpaper
from”,如下:
private
void
startWallpaper()
{
showWorkspace(true);
final
Intent
pickWallpaper
=
new
Intent(Intent.ACTION_SET_WALLPAPER);
Intent
chooser
=
Intent.createChooser(pickWallpaper,
getText(R.string.chooser_wallpaper));
//
NOTE:
Adds
a
configure
option
to
the
chooser
if
the
wallpaper
supports
it
startActivityForResult(chooser,
REQUEST_PICK_WALLPAPER);
}
其中,R.string.chooser_wallpaper對應的字串內容就是”Choose
wallpaper
from”,定義在Launcher2的Strings.xml中

㈥ 如何將Android中的標題欄自定義

原裝的Android標題欄配色比較單調,就是黑色的一坨,現在假設你的軟體需要獨自添加標題欄,這樣不僅美觀而且可以將進度條等加進去,如何實現:

方法一、在你的那張Activity中onCreate方法中加上下面代碼:

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main); //軟體activity的布局
但是新的問題又來了,這樣是無法深層的定製標題欄的,比如原有的高度和背景都沒有發生變化,那有沒有好的方法呢?答案是有的、

方法二:

因此先定義一個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"
就可以了
<activity android:name=".Test"
android:theme = "@style/test" //就在這里
>
</activity>

之後藉助於設置自定義的標題欄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開發中如何自定義標題欄

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">#</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值。

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

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

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

熱點內容
醫院新冠肺炎疫情防控演練腳本 發布:2024-04-27 04:04:45 瀏覽:652
天津智慧網關伺服器雲伺服器 發布:2024-04-27 03:56:51 瀏覽:422
移門製作下料尺寸演算法 發布:2024-04-27 03:15:02 瀏覽:641
c語言5常量 發布:2024-04-27 02:38:49 瀏覽:991
源碼怎麼搭建 發布:2024-04-27 02:33:44 瀏覽:97
java獲取參數 發布:2024-04-27 02:22:21 瀏覽:501
unixlinuxwindows 發布:2024-04-27 02:10:55 瀏覽:445
nginx禁止ip訪問網站 發布:2024-04-27 02:05:43 瀏覽:845
webrtc伺服器搭建哪家價格低 發布:2024-04-27 01:30:08 瀏覽:141
oracle資料庫無法啟動 發布:2024-04-27 01:29:20 瀏覽:613