基本信息
源码名称:android BaseActivity 示例代码分享
源码大小:1.39KB
文件格式:.zip
开发语言:Java
更新时间:2015-02-05
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍


BaseActivity 如下:

/**
 * Activity
 * 
 * @author coder
 * 
 */
public class BaseActivity extends Activity {

	private View titleView;
	private TextView tv_title;
	private Button btn_left, btn_right;

	private LinearLayout ly_content;
	// 
	private View contentView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.common_title);
		titleView = findViewById(R.id.titleView);
		tv_title = (TextView) titleView.findViewById(R.id.tv_title);
		btn_left = (Button) titleView.findViewById(R.id.btn_left);
		btn_right = (Button) titleView.findViewById(R.id.btn_right);

		ly_content = (LinearLayout) findViewById(R.id.ly_content);
	}

	/***
	 * 
	 * 
	 * @param resId
	 *            ID
	 */
	public void setContentLayout(int resId) {

		LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		contentView = inflater.inflate(resId, null);
		LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.FILL_PARENT);
		contentView.setLayoutParams(layoutParams);
		contentView.setBackgroundDrawable(null);
		if (null != ly_content) {
			ly_content.addView(contentView);
		}

	}

	/***
	 * 
	 * 
	 * @param view
	 *            View
	 */
	public void setContentLayout(View view) {
		if (null != ly_content) {
			ly_content.addView(view);
		}
	}

	/**
	 * View
	 * 
	 * @return
	 */
	public View getLyContentView() {

		return contentView;
	}

	/**
	 * 
	 * 
	 * @return
	 */
	public Button getbtn_left() {
		return btn_left;
	}

	/**
	 * 
	 * 
	 * @return
	 */
	public Button getbtn_right() {
		return btn_right;
	}

	/**
	 * 
	 * 
	 * @param title
	 */
	public void setTitle(String title) {

		if (null != tv_title) {
			tv_title.setText(title);
		}

	}

	/**
	 * 
	 * 
	 * @param resId
	 */
	public void setTitle(int resId) {
		tv_title.setText(getString(resId));
	}

	/**
	 * 
	 * 
	 * @param resId
	 */
	public void setbtn_leftRes(int resId) {
		if (null != btn_left) {
			btn_left.setBackgroundResource(resId);
		}

	}

	/**
	 * 
	 * 
	 * @param bm
	 */
	public void setbtn_leftRes(Drawable drawable) {
		if (null != btn_left) {
			btn_left.setBackgroundDrawable(drawable);
		}

	}

	/**
	 * 
	 * 
	 * @param resId
	 */
	public void setbtn_rightRes(int resId) {
		if (null != btn_right) {
			btn_right.setBackgroundResource(resId);
		}
	}

	/**
	 * 
	 * 
	 * @param drawable
	 */
	public void setbtn_rightRes(Drawable drawable) {
		if (null != btn_right) {
			btn_right.setBackgroundDrawable(drawable);
		}
	}

	/**
	 * 
	 */
	public void hideTitleView() {

		if (null != titleView) {
			titleView.setVisibility(View.GONE);
		}
	}

	/**
	 * 
	 */
	public void hidebtn_left() {

		if (null != btn_left) {
			btn_left.setVisibility(View.GONE);
		}

	}

	/***
	 * 
	 */
	public void hidebtn_right() {
		if (null != btn_right) {
			btn_right.setVisibility(View.GONE);
		}

	}

	public BaseActivity() {

	}

}

调用方法如下:

public class TwoBtnActivity extends BaseActivity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentLayout(R.layout.two);

		//
		setTitle("");



		// 
		getbtn_left().setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				onBackPressed();

			}
		});

	}

}