Android中自定义标题栏(一)

activity代码

package com.android.demo;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.TextView;

public class MytestActivity extends Activity {
	TextView myText;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.titlebar);
        
        myText = (TextView)findViewById(R.id.myText);
        myText.setText("自定义标题栏");
    }
}

layout/titlebar代码

<?xml version="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/myText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     ></TextView>
效果图

Android中自定义标题栏(一)_第1张图片

你可能感兴趣的:(Android中自定义标题栏(一))