Android — How to disscociate the name of the application from the titlebar?

元气小坏坏 提交于 2019-12-08 03:20:57

问题


I added a custom title-bar to an android application and this titlebar (which is a plain png) shows up inside the main activity. The problem is that the main activity also defines the name of the application using the label tag like this:

<activity android:name=".MainActivity" 
                  android:theme="@style/customTheme"
                  android:screenOrientation="portrait"
                  android:label="@string/app_name">
              <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
              </intent-filter>
 </activity>

And this label is also reported on the titlebar! How to dissociate the two? (Like basically, still be able to give a name to the application without affecting my custom title-bar).

Thanks!


回答1:


You can change the header of any activity by using setTitle("THE TITLE"); in the java code for the page. If you want to use a string defined in the XML FILES, you can use setTitle(R.string.stringName).




回答2:


My opinion is to create your own custom title bar in the top of the screen and set the no title bar option in the manifest for the activity.

android:theme="@android:style/Theme.NoTitleBar"



回答3:


try changing the label of your mainactivity to something like this android:label="@string/main_header" and define the string header in the strings.xml...

hope this good help you...



来源:https://stackoverflow.com/questions/6574729/android-how-to-disscociate-the-name-of-the-application-from-the-titlebar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!