如何更改android活动标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10138007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change android Activity label
提问by noname
I have created an Activity and declared in Manifest file. But I would like to re-use the same Activity for other purpose.
我创建了一个活动并在清单文件中声明。但我想将同一个 Activity 重新用于其他目的。
<activity
android:configChanges="orientation|keyboardHidden"
android:label="Main Menu"
android:name=".MainMenu"
android:theme="@android:style/Theme.Light" >
</activity>
I need to change the Label dynamically. Thanks in Advance
我需要动态更改标签。提前致谢
回答by Shubhayu
Use
用
setTitle(int titleId)
or
或者
setTitle(CharSequence title)
回答by SamSPICA
public class YourActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
setTitle(R.string.your_title);
setContentView(R.layout.main);
}
}
回答by waqaslam
You need to use setTitlefor this:
您需要为此使用setTitle:
setTitle(R.string.your_title);
//or
setTitle("new title");
回答by waqaslam
I have the same problem, Try this in onCreate
it's work for me!
我有同样的问题,试试这个onCreate
对我有用!
public class YourActivityName extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
setTitle("Your Title");
}
}
回答by Triple Hash
You can define the string in res/string.xml file and then add android:label to the AndroidMenifest.xml file
您可以在 res/string.xml 文件中定义字符串,然后将 android:label 添加到 AndroidMenifest.xml 文件中
string.xml code
<string name="string_name">text to display</string>
AndroidMenifest.xml code
<activity android:name=".SomeActivity"
android:label="@string/string_name"/>
回答by Bhavin
if(Condition)
{
setTitle("Your Title");
}
else
{
// your Default Title from Manifest
}
Try to use this line.
尝试使用这条线。
回答by Rahul Joshi
In your Manifest file
在您的清单文件中
Initially, your code was like this.
最初,您的代码是这样的。
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".NumbersActivity" />
<activity android:name=".FamilyMembersActivity" />
<activity android:name=".ColorsActivity" />
<activity android:name=".PhrasesActivity" />
</activity>
</application>
But after changes to add Labels.
但更改后添加标签。
<activity android:name=".NumbersActivity" android:label="Numbers" />
<activity android:name=".FamilyMembersActivity" android:label="Family Members" />
<activity android:name=".ColorsActivity" android:label="Colors" />
<activity android:name=".PhrasesActivity" android:label="Phrases" >
</activity>
</application>
is the optimum way to change the Label name.
是更改标签名称的最佳方式。
courtesy.(ryanwaite28)
礼貌。(ryanwaite28)
回答by ryanwaite28
Static, not Dynamic
静态,而不是动态
Go to your AndroidManifest.xml file and add the android:label attribute to the activity tag you want, like this:
转到您的 AndroidManifest.xml 文件并将 android:label 属性添加到您想要的活动标签,如下所示:
<activity android:name=".name" android:label="label"/>
回答by shoooka
android:label="any word you want"/>
android:label="任何你想要的词"/>