Android 自定义标题栏
2011-10-21 15:12
375 查看
转自:http://lovezhou.iteye.com/blog/849953
核心代码:
//设置标志为自定义标题栏
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.custom_title);
//设置自定义标题栏,该句必须放在setContentView之后
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
效果图:
![](http://dl.iteye.com/upload/attachment/374005/eb652ff1-b3e7-333a-ba26-7db3ba43609b.png)
Java代码
![](http://lovezhou.iteye.com/images/icon_star.png)
![](http://lovezhou.iteye.com/images/spinner.gif)
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());
}
});
}
}
核心代码:
//设置标志为自定义标题栏
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.custom_title);
//设置自定义标题栏,该句必须放在setContentView之后
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
效果图:
![](http://dl.iteye.com/upload/attachment/374005/eb652ff1-b3e7-333a-ba26-7db3ba43609b.png)
Java代码
![](http://lovezhou.iteye.com/images/icon_star.png)
![](http://lovezhou.iteye.com/images/spinner.gif)
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());
}
});
}
}
相关文章推荐
- android带返回按钮的自定义标题栏
- (转自ztp800201) Android - 自定义标题栏(在标题栏中增加按钮和文本居中)
- Android-自定义标题栏
- Android自定义标题栏
- android 自定义标题栏
- android 自定义view——常用的标题栏
- [置顶] xamarin android自定义标题栏(自定义属性、回调事件)
- 解决android自定义标题栏充满的问题
- Android 应用程序窗体显示状态操作(显示隐藏标题栏或自定义窗体大小)
- Android自定义实现微信标题栏
- Android自定义标题栏
- Android:自定义标题栏
- android自定义标题栏时候you cannot combine custom titles with other title
- Android:自定义标题栏
- android 制作自定义标题栏
- 【Android】自定义标题栏 (解决了标题栏两侧空隙问题)
- Android--自定义标题栏之显示网页加载进度
- Android自定义标题栏
- 【Android】自定义标题栏
- android带返回按钮的自定义标题栏布局文件详解