當前位置:首頁 » 安卓系統 » android標題欄按鈕

android標題欄按鈕

發布時間: 2022-04-25 05:51:55

① android的Activity控制項標題欄的屬性怎麼設置啊

Activity的標題欄,叫ActionBar,ActionBar位於Activity的頂部,可用來顯示activity的標題、Icon、Actions和一些用於交互的View。它也可被用於應用的導航。
ActionBar
標題欄常用屬性:
showAsAction屬性用來定義每個Action是如何顯示的
always表示永遠顯示在ActionBar中,如果屏幕空間不夠則無法顯示
ifRoom表示屏幕空間夠的情況下顯示在ActionBar中,不夠的話就顯示在overflow中
never則表示永遠顯示在overflow中

② 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怎麼寫個自己的標題欄

我們做應用的時候經常想有自己的標題欄,在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的MainActivity的自帶標題欄中能否加入圖片按鈕呢,點擊觸發事件,必須要自定義一個標題欄嗎

建議你取消系統TitleBar然後自己定義一個,目前大多數開發都是自己定義TitleBar,可以將TitleBar定義成一個控制項,也方便後期的使用方便。而且系統默認的TitleBar是無法完成你需要的操作,除非你引入V7 jar包 Activity繼承ActionBarActivity,但這樣有點大才小用了,所以不建議使用。

⑤ 關於Android中標題欄上的這個菜單

這個可以用官方的FloatingActionButton做出來,需要Demo的話請追問。

⑥ 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如何自定義標題欄百度到的我都試了,沒用。用的是as

1、在layout下創建一個titlebtn.xml文件,內容如下:

⑧ 如何在android標題欄中添加按鈕

Android在標題欄加按鈕_網路文庫
http://wenku..com/link?url=D93O4XxbjID1hxTF5Y7dhV14mx-aadsaHSSHCSyqzwvr7ug0Rycd-TFy9QVACn91Tzw_

Android中標題欄添加按鈕

現在很多的Android程序都在標題欄上都顯示了一些按鈕和標題,如下圖:

下面通過實例來看一下如何實現。
1、在layout下創建一個titlebtn.xml文件,內容如下: [html] view plainprint?
1. <?xml version="1.0" encoding="utf-8"?>
2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andr
oid"
3. android:orientation="horizontal" 4. android:layout_width="fill_parent" 5. android:layout_height="fill_parent"> 6.
7. <ImageButton
8. android:id="@+id/imageButton1" 9. android:layout_width="wrap_content" 10. android:layout_height="wrap_content" 11. android:background="#00000000" 12. android:layout_centerVertical="true" 13. android:layout_alignParentLeft="true" 14. android:src="@drawable/prv" /> 15.
16. <TextView
17. android:layout_width="wrap_content"

⑨ android 在標題欄中加了個icon,長按之後彈出了奇怪的東西,如圖,大概會出現兩三秒,請問大家是什麼原因

這個相當於Windows系統中的「工具提示」,在Windows系統中,把滑鼠放在按鈕上一段時間,會顯示這個按鈕的名稱,android也一樣,像你所說的,長按按鈕後彈出的就是這個按鈕的名稱,讓用戶知道如何操作

熱點內容
濕地下載ftp 發布:2024-05-19 21:46:10 瀏覽:486
java二分查找演算法 發布:2024-05-19 21:37:38 瀏覽:347
所有編程語言 發布:2024-05-19 21:33:55 瀏覽:665
c語言1到10的階乘的和 發布:2024-05-19 21:32:25 瀏覽:628
php匹配標點符號 發布:2024-05-19 21:14:49 瀏覽:753
可以拍照輸入的c語言編譯器 發布:2024-05-19 21:09:47 瀏覽:181
解壓升降機 發布:2024-05-19 20:51:11 瀏覽:967
請稍作停留密碼是什麼意思 發布:2024-05-19 20:37:12 瀏覽:244
linux結束符 發布:2024-05-19 20:33:05 瀏覽:817
招標伺服器雲 發布:2024-05-19 20:04:19 瀏覽:584