改变这个标题MainActivity就像这很多方法一样。
正常方式,
您可以通过设置它们来更改每个屏幕的标题(即活动)Android:label
<activity android:name=".Hello_World"
android:label="This is the Hello World Application">
</activity>
自定义 - 标题 - 栏
但是如果你想以你的方式自定义标题栏,即想要放置图像图标和自定义文本,那么下面的代码正在为我运行:
主要的.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</LinearLayout>
标题栏.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400px"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ImageView android:id="@+id/ImageView01"
android:layout_width="57px"
android:layout_height="wrap_content"
android:background="@drawable/icon1">
</ImageView>
<TextView
android:id="@+id/myTitle"
android:text="This is my new title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="@color/titletextcolor"
/>
</LinearLayout>
标题栏.java
public class TitleBar extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
if ( customTitleSupported ) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
}
final TextView myTitleText = (TextView) findViewById(R.id.myTitle);
if ( myTitleText != null ) {
myTitleText.setText("NEW TITLE");
// user can also set color using "Color" and then "Color value constant"
// myTitleText.setBackgroundColor(Color.GREEN);
}
}
}
字符串.xml
strings.xml文件在values 文件夹下定义。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Set_Text_TitleBar!</string>
<string name="app_name">Set_Text_TitleBar</string>
<color name="titlebackgroundcolor">#3232CD</color>
<color name="titletextcolor">#FFFF00</color>
</resources>