導航:首頁 > 操作系統 > android獲取標題欄

android獲取標題欄

發布時間:2022-08-20 14:05:39

android 狀態欄和標題欄具體是哪裡

就我理解,標題欄是手機左上最頂上,顯示中國移動,安全衛士,或者當前運行軟體的地方,手機的頂部。右邊顯示信號,電量,網速等等是狀態欄。
下拉就會出現通知欄。
至於導航欄是手機最下面的返回,HOME,主頁三個鍵,有些是一個按鈕。

② Android 在 extend ListActivity 的情況下如何顯示標題欄

其實是有的,在ListActivity中有一個方法很容易被忽略,ensureList(),這是唯一一個設置了layout的地方,但是不是在oncreate中設置的,listActivity沒有實現onCreate方法,
繼續找,發現在onRestoreInstanceState(), setListAdapter()和getListView()中調用了,也就是說在這3個方法中都有可能會執行setContentView方法,
知道這個就好辦了,
解決方法一:在oncreate方法中調用getListView()代替掉上面的setContentView(R.layout.main)

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
//代替掉setContentView
getListView();
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
}

③ android怎麼不顯示標題欄

1.安卓標題欄不顯示的原因
活動是按照教材(Android第一行代碼)上繼承的Activity,但打開主題的styles.xml,會發現
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
設定中用到了AppCompat的主題
解決辦法就是讓所有的活動都繼承 AppCompatActivity就行了,如下:
public class 活動 extends AppCompatActivity

2.標題欄無法隱藏原因
在《第一行代碼》上學習做自定義標題欄,需要將系統自帶的標題欄隱藏掉,使用自定義的標題欄,結果發現,requestWindowFeature(Window.FEATURE_NO_TITLE); 這句代碼無效,標題欄無法隱藏
活動的繼承
public class FirstActivity extends AppCompatActivity
因為活動是繼承AppCompatActivity,所以
requestWindowFeature(Window.FEATURE_NO_TITLE);
這句失效了
解決方法有兩種
(1)將AppCompatActivity改為Activity,此時 requestWindowFeature(Window.FEATURE_NO_TITLE);是有效的

(2)在onCreate()方法中加入如下代碼:
if (getSupportActionBar() != null){
getSupportActionBar().hide();
}
這樣就可以隱藏標題欄了

④ android中怎樣獲取標題欄和狀態欄

android獲取標題欄和狀態欄的話,你
網路一下
關鍵字,有很多博客講解過的,看看就知道了。

⑤ 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如何獲取系統高度、標題欄和狀態欄高度

getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);///取得整個視圖部分,注意,如果你要設置標題樣式,這個必須出現在標題樣式之後,否則會出錯
int top = rect.top;////狀態欄的高度,所以rect.height,rect.width分別是系統的高度的寬度
View v = getWindow().findViewById(Window.ID_ANDROID_CONTENT);///獲得根視圖
int top2 = v.getTop();///狀態欄標題欄的總高度,所以標題欄的高度為top2-top
int width = v.getWidth();///視圖的寬度,這個寬度好像總是最大的那個
int height = v.getHeight();////視圖的高度,不包括狀態欄和標題欄
如果只想取得屏幕大小,可以用
Display display = getWindowManager().getDefaultDisplay() ;
display.getWidth();
display.getHeight();代碼見@Overridepublic void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
Rect frame = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
// 狀態欄高度
int statusBarHeight = frame.top;
View v = getWindow().findViewById(Window.ID_ANDROID_CONTENT);
int contentTop = v.getTop();
// statusBarHeight是上面所求的狀態欄的高度
int titleBarHeight = contentTop - statusBarHeight;
textView = (TextView) findViewById(R.id.textView1);
textView.setText(標題欄的高度 + Integer.toString(titleBarHeight) +

+ 標題欄高度 + statusBarHeight +
+ 視圖的寬度 + v.getWidth()
+
+ 視圖的高度(不包含狀態欄和標題欄) + v.getHeight());}效果:

⑦ Android,恢復隱藏掉的標題欄

1. 可以不用系統的,自己重新設計一個,然後自己想怎麼控制就怎麼控制了。

⑧ Android開發如何去除標題欄title

android中取出標題欄,主要是通過設置windows的模式,可以通過在主配置文件或者代碼中進行設置:

1.使用Window.FEATURE_NO_TITLE設置沒有標題,當然也有很多其他屬性:

java">publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉標題欄,一定要在setContentView之前
setContentView(R.layout.history);
}

2.在android工程中的主配置文件manifest.xml中配置

<applicationandroid:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"><!--NoTitleBar就是沒有標題欄-->


除了沒有標題欄以外,開發者還可以自定義標題欄,如下很多屬性的解釋:

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:標題欄右側的圖標

⑨ android 怎麼去除標題欄高度

通過獲取內容區域的 rect 的 top 值就是狀態欄和標題欄的高度,也就可以得到標題欄的高度了
int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();

int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();

注意:

不能再onCreat()和onResume()中調用,那樣取的值會是0,可以在onWindowFocusChanged()中取得。

閱讀全文

與android獲取標題欄相關的資料

熱點內容
qq小程序雲伺服器和 瀏覽:739
方舟伺服器怎麼玩才好玩 瀏覽:557
單片機的部件 瀏覽:621
編譯原理遍的過程 瀏覽:252
python讀取json字元串 瀏覽:62
ubuntu1404安裝php 瀏覽:628
lua能編譯嗎 瀏覽:116
思仙怎麼看伺服器 瀏覽:658
php微信圖片防盜鏈 瀏覽:798
安卓1怎麼讀音 瀏覽:291
農業app怎麼開通快捷支付 瀏覽:910
pythonredisdict 瀏覽:385
如何攻擊別人網賭伺服器 瀏覽:880
隱私與應用加密的圖案密碼 瀏覽:38
陳情令王一博解壓 瀏覽:39
c編譯器使用說明 瀏覽:707
鄭州前端程序員私活有風險嗎 瀏覽:14
小型螺桿機壓縮機 瀏覽:520
成人解壓最好的方法 瀏覽:52
最小製冷壓縮機 瀏覽:492