你的位置:首页 > 操作系统

[操作系统]android 自定义title


package com.xiangyu.su;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup.LayoutParams;import android.widget.Button;import android.widget.FrameLayout;import android.widget.TextView;import android.widget.Toast;public class BasicActivity extends Activity implements OnClickListener {	private TextView mTitleTextView;	private Button mBackwardButton;	private Button mForwardButton;	private FrameLayout mContentLayout;	@Override	protected void onCreate(Bundle savedInstanceState) {		super.onCreate(savedInstanceState);		setupViews();	}	private void setupViews(){		super.setContentView(R.layout.activity_title);		mTitleTextView=(TextView) findViewById(R.id.text_title);		mContentLayout=(FrameLayout) findViewById(R.id.layout_content);		mBackwardButton=(Button) findViewById(R.id.button_backward);		mForwardButton=(Button) findViewById(R.id.button_forward);		mBackwardButton.setOnClickListener(this);		mForwardButton.setOnClickListener(this);	}	protected void showBackwardView(int backwardResid,boolean show){		if(mBackwardButton!=null){			if(show){				mBackwardButton.setText(backwardResid);				mBackwardButton.setVisibility(View.VISIBLE);			}else{				mBackwardButton.setVisibility(View.INVISIBLE);			}		}	}	protected void showForwardView(int forwardResid,boolean show){		if(mForwardButton!=null){			if(show){				mForwardButton.setVisibility(View.VISIBLE);				mForwardButton.setText(forwardResid);			}else{				mForwardButton.setVisibility(View.INVISIBLE);			}		}	}	private void onBackward(View backwardView){		Toast.makeText(this, "返回", Toast.LENGTH_SHORT).show();	}	protected void onForward(View forwardView) {    Toast.makeText(this, "提交", Toast.LENGTH_LONG).show();  }  @Override  public void setTitle(int titleId) {    mTitleTextView.setText(titleId);  }  @Override  public void setTitle(CharSequence title) {    mTitleTextView.setText(title);  }  @Override  public void setTitleColor(int textColor) {    mTitleTextView.setTextColor(textColor);  }  @Override  public void setContentView(int layoutResID) {    mContentLayout.removeAllViews();    View.inflate(this, layoutResID, mContentLayout);    onContentChanged();  }  @Override  public void setContentView(View view) {    mContentLayout.removeAllViews();    mContentLayout.addView(view);    onContentChanged();  }  /* (non-Javadoc)   * @see android.app.Activity#setContentView(android.view.View, android.view.ViewGroup.LayoutParams)   */  @Override  public void setContentView(View view, LayoutParams params) {    mContentLayout.removeAllViews();    mContentLayout.addView(view, params);    onContentChanged();  }	@Override	public void onClick(View v) {		switch (v.getId()) {		case R.id.button_backward:			onBackward(v);			break;		case R.id.button_forward:			onForward(v);			break;		default:			break;		}	}  }

  

<?

  

<?

  使用方法:

继承这个activity,重写onclick()方法