导航:首页 > 操作系统 > 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获取标题栏相关的资料

热点内容
ubuntu1404安装php 浏览:628
lua能编译吗 浏览:106
思仙怎么看服务器 浏览:656
php微信图片防盗链 浏览:796
安卓1怎么读音 浏览:287
农业app怎么开通快捷支付 浏览:908
pythonredisdict 浏览:383
如何攻击别人网赌服务器 浏览:878
隐私与应用加密的图案密码 浏览:34
陈情令王一博解压 浏览:35
c编译器使用说明 浏览:705
郑州前端程序员私活有风险吗 浏览:14
小型螺杆机压缩机 浏览:518
成人解压最好的方法 浏览:50
最小制冷压缩机 浏览:490
xampp支持python 浏览:367
深圳周立功单片机 浏览:61
圆上点与点之间角度算法 浏览:869
怎么知道微信关联了哪些app 浏览:702
android事件驱动 浏览:888