android自定义标题栏
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呗