首页 > 代码库 > android baseActivity
android baseActivity
package newdemo.jeno.designdemo.activitynew;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import newdemo.jeno.designdemo.R;
import newdemo.jeno.designdemo.view.ToolBarBean;
/**
* Created by songjiabin1 on 2016/9/18.
*/
public abstract class BaseActivity extends AppCompatActivity {
private TextView tvTitle;
private ImageView ivTopBack;
private Toolbar toolbar;
private ToolBarBean toolBarBean;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//此为积累的activity
setContentView(getLayout());
inintData();
}
/**
* 得到布局文件
*
* @return
*/
public abstract int getLayout();
/**
* 初始化view
*/
protected abstract void inintData();
protected <T extends View> T findView(int resourcesId) {
return (T) findViewById(resourcesId);
}
protected ToolBarBean getToolbar() {
if (toolBarBean == null) {
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolBarBean = new ToolBarBean(this, toolbar);
}
return toolBarBean;
}
}
package newdemo.jeno.designdemo.view;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import newdemo.jeno.designdemo.R;
/**
* Created by songjiabin1 on 2016/9/18.
*/
public class ToolBarBean {
private TextView tvTitle;
private ImageView ivToolbarBack;
private AppCompatActivity context;
private Toolbar toolbar;
public ToolBarBean(AppCompatActivity context, Toolbar toolbar) {
this.context = context;
this.toolbar = toolbar;
ivToolbarBack = (ImageView) toolbar.findViewById(R.id.iv_topBack);
tvTitle = (TextView) toolbar.findViewById(R.id.tvTitle);
}
/**
* 进行回退
*/
public ToolBarBean setBack() {
ivToolbarBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
context.finish();
}
});
return this;
}
/**
* 设置标题
*/
public ToolBarBean setTitle(String title) {
tvTitle.setText(title);
return this;
}
/**
* 自定义的回退
*/
public ToolBarBean setCustomBack(View.OnClickListener onClickListener) {
ivToolbarBack.setOnClickListener(onClickListener);
return this;
}
}
android baseActivity
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。