核心代码:
//设置标志为自定义标题栏
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.custom_title);
//设置自定义标题栏,该句必须放在setContentView之后
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
效果图:
[img]http://dl.iteye.com/upload/attachment/374005/eb652ff1-b3e7-333a-ba26-7db3ba43609b.png[/img]
//设置标志为自定义标题栏
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.custom_title);
//设置自定义标题栏,该句必须放在setContentView之后
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
效果图:
[img]http://dl.iteye.com/upload/attachment/374005/eb652ff1-b3e7-333a-ba26-7db3ba43609b.png[/img]
package com.zhou.activity;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class CustomTitleActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//关键代码
//设置自定义标题栏标志
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
//显示页面
setContentView(R.layout.custom_title);
//设置自定义标题栏,改句必须放在setContentView之后
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
final TextView leftText = (TextView) findViewById(R.id.left_text);
final TextView rightText = (TextView) findViewById(R.id.right_text);
final EditText leftTextEdit = (EditText) findViewById(R.id.left_text_edit);
final EditText rightTextEdit = (EditText) findViewById(R.id.right_text_edit);
Button leftButton = (Button) findViewById(R.id.left_text_button);
Button rightButton = (Button) findViewById(R.id.right_text_button);
//按钮事件处理
leftButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
leftText.setText(leftTextEdit.getText());
}
});
rightButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
rightText.setText(rightTextEdit.getText());
}
});
}
}