简体   繁体   English

如何在此android示例中添加TitleBar?

[英]How to add TitleBar in this android example?

I am new to implement the ListView with section. 我是刚实现ListView with部分的新手。

I have use this application to implement the section to my list view. 我已使用应用程序将列表部分实现为我的列表视图。

Now I want to add the Titlebar that display the application page title. 现在,我想添加显示应用程序页面标题的标题栏。 Then where do I have to make a change? 那我必须在哪里进行更改? In the xml file or in the Java file? 在xml文件中还是在Java文件中?

Please refer the example and let me tell what should I have to change to make Titlebar for my app. 请参考示例,让我告诉我要为我的应用制作标题栏需要更改什么。

There are two ways to change title bar for your activity: 有两种更改活动标题栏的方法:

  1. Design time (that is, change title in AndroidManifest.xml file). 设计时间 (即,更改AndroidManifest.xml文件中的标题)。
  2. By coding (that is, you can code to change the activity title). 通过编码 (即,您可以编码以更改活动标题)。

Example for 1st: 第一个示例:

you can Change the Title of each screen (ie Activity) by setting their Android:label inside the AndroidManifest.xml file: 您可以通过在AndroidManifest.xml文件中设置它们的Android:label来更改每个屏幕的标题(即“活动”):

<activity android:name=".Hello_World"
                  android:label="This is the Hello World Application">
   </activity>

And yes, to display customized title bar for your activity, go through this answer: How to change the text on the action bar 是的,要显示您的活动的自定义标题栏,请经历以下答案: 如何更改操作栏上的文本

Try this... 尝试这个...

final Activity activity = this;
activity.setTitle("Settings");

if you disabled the title bar using, this.requestWindowFeature(Window.FEATURE_NO_TITLE); 如果使用禁用了标题栏,则this.requestWindowFeature(Window.FEATURE_NO_TITLE); remove it. 去掉它。

(OR) (要么)

Try this.. 尝试这个..

        final Activity activity = this;
        this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.settings);
        activity.setTitle("Settings");

In your AndroidManifest.xml file you have a section for each activity that looks like this 在AndroidManifest.xml文件中,每个活动都有一个类似于以下内容的部分

    <activity
        android:label="Your Activity"
        android:name=".YourActivity" />

where the android:label tag defines what the text in the titlebar is. android:label标签定义了标题栏中的文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM