当前位置:首页 » 安卓系统 » 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-05-07 15:58:35 浏览:524
ftp是什么检测器 发布:2024-05-07 15:37:59 浏览:403
重庆电信服务器租用教学云主机 发布:2024-05-07 15:28:05 浏览:73
python声明对象 发布:2024-05-07 15:28:03 浏览:128
存储过程的应用场景 发布:2024-05-07 15:12:16 浏览:613
车内配置怎么看 发布:2024-05-07 15:11:39 浏览:209
outlook已发送文件夹 发布:2024-05-07 14:08:13 浏览:31
佛系源码 发布:2024-05-07 14:04:03 浏览:674
php蚂蚁 发布:2024-05-07 13:49:22 浏览:401
phpfpmpid 发布:2024-05-07 13:44:29 浏览:521