If you think the Android project cube-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package in.srain.cube.mints.base;
/*fromwww.java2s.com*/import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import in.srain.cube.R;
publicclass TitleHeaderBar extends RelativeLayout {
private TextView mCenterTitleTextView;
private ImageView mLeftReturnImageView;
private RelativeLayout mLeftViewContainer;
private RelativeLayout mRightViewContainer;
private RelativeLayout mCenterViewContainer;
private String title;
public TitleHeaderBar(Context context) {
this(context, null);
}
public TitleHeaderBar(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public TitleHeaderBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
LayoutInflater.from(context).inflate(R.layout.cube_mints_base_header_bar_title, this);
mLeftViewContainer = (RelativeLayout) findViewById(R.id.ly_title_bar_left);
mCenterViewContainer = (RelativeLayout) findViewById(R.id.ly_title_bar_center);
mRightViewContainer = (RelativeLayout) findViewById(R.id.ly_title_bar_right);
mLeftReturnImageView = (ImageView) findViewById(R.id.iv_title_bar_left);
mCenterTitleTextView = (TextView) findViewById(R.id.tv_title_bar_title);
}
public ImageView getLeftImageView() {
return mLeftReturnImageView;
}
public TextView getTitleTextView() {
return mCenterTitleTextView;
}
publicvoid setTitle(String title) {
this.title = title;
mCenterTitleTextView.setText(title);
}
private RelativeLayout.LayoutParams makeLayoutParams(View view) {
ViewGroup.LayoutParams lpOld = view.getLayoutParams();
RelativeLayout.LayoutParams lp = null;
if (lpOld == null) {
lp = new RelativeLayout.LayoutParams(-2, -1);
} else {
lp = new RelativeLayout.LayoutParams(lpOld.width, lpOld.height);
}
return lp;
}
/**
* set customized view to left side
*
* @param view the view to be added to left side
*/publicvoid setCustomizedLeftView(View view) {
mLeftReturnImageView.setVisibility(GONE);
RelativeLayout.LayoutParams lp = makeLayoutParams(view);
lp.addRule(CENTER_VERTICAL);
lp.addRule(ALIGN_PARENT_LEFT);
getLeftViewContainer().addView(view, lp);
}
/**
* set customized view to left side
*
* @param layoutId the xml layout file id
*/publicvoid setCustomizedLeftView(int layoutId) {
View view = inflate(getContext(), layoutId, null);
setCustomizedLeftView(view);
}
/**
* set customized view to center
*
* @param view the view to be added to center
*/publicvoid setCustomizedCenterView(View view) {
mCenterTitleTextView.setVisibility(GONE);
RelativeLayout.LayoutParams lp = makeLayoutParams(view);
lp.addRule(CENTER_IN_PARENT);
getCenterViewContainer().addView(view, lp);
}
/**
* set customized view to center
*
* @param layoutId the xml layout file id
*/publicvoid setCustomizedCenterView(int layoutId) {
View view = inflate(getContext(), layoutId, null);
setCustomizedCenterView(view);
}
/**
* set customized view to right side
*
* @param view the view to be added to right side
*/publicvoid setCustomizedRightView(View view) {
RelativeLayout.LayoutParams lp = makeLayoutParams(view);
lp.addRule(CENTER_VERTICAL);
lp.addRule(ALIGN_PARENT_RIGHT);
getRightViewContainer().addView(view, lp);
}
public RelativeLayout getLeftViewContainer() {
return mLeftViewContainer;
}
public RelativeLayout getCenterViewContainer() {
return mCenterViewContainer;
}
public RelativeLayout getRightViewContainer() {
return mRightViewContainer;
}
publicvoid setLeftOnClickListener(OnClickListener l) {
mLeftViewContainer.setOnClickListener(l);
}
publicvoid setCenterOnClickListener(OnClickListener l) {
mCenterViewContainer.setOnClickListener(l);
}
publicvoid setRightOnClickListener(OnClickListener l) {
mRightViewContainer.setOnClickListener(l);
}
}