当前位置:首页 » 安卓系统 » 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也一样,像你所说的,长按按钮后弹出的就是这个按钮的名称,让用户知道如何操作

热点内容
推荐编程课 发布:2025-05-15 22:34:12 浏览:615
表拒绝访问 发布:2025-05-15 22:29:37 浏览:976
电脑怎样解压文件 发布:2025-05-15 22:25:32 浏览:438
dns服务器怎么看 发布:2025-05-15 22:17:27 浏览:150
3dm的压缩包 发布:2025-05-15 22:09:23 浏览:661
和存储字长 发布:2025-05-15 21:54:09 浏览:514
用什么写c语言 发布:2025-05-15 21:35:56 浏览:418
linux读取u盘 发布:2025-05-15 21:32:13 浏览:508
c语言dos 发布:2025-05-15 21:18:17 浏览:664
sci编译英文 发布:2025-05-15 21:16:57 浏览:383