加入ActionBar返回按钮以及监听事件

This commit is contained in:
zengfantian 2015-02-28 18:46:53 +08:00
parent 8425991358
commit c0c69f328e
21 changed files with 120 additions and 2 deletions

View File

@ -2,13 +2,17 @@ package com.zftlive.android.base;
import java.lang.ref.WeakReference;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import com.zftlive.android.MApplication;
import com.zftlive.android.R;
import com.zftlive.android.common.ActionBarManager;
/**
* android 系统中的四大组件之一Activity基类
@ -112,4 +116,14 @@ public abstract class BaseActivity extends Activity implements IBaseActivity{
public Operation getOperation(){
return this.mBaseOperation;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -0,0 +1,18 @@
package com.zftlive.android.common;
import com.zftlive.android.R;
import android.app.ActionBar;
import android.content.Context;
public class ActionBarManager {
public static void initActionBar(Context mContext,ActionBar actionBar){
actionBar.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.actionbar_bg));
}
public static void initBackTitle(Context mContext,ActionBar actionBar){
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
}
}

View File

@ -19,6 +19,7 @@ import android.widget.TextView;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.base.BaseAdapter;
import com.zftlive.android.common.ActionBarManager;
/**
* Sample列表集合界面--自动收集AndroidManifest.xml配置
@ -69,6 +70,8 @@ public class MainActivity extends BaseActivity {
DemoActivityAdapter mAdapter = new DemoActivityAdapter(this);
mAdapter.addItem(getListData());
mListView.setAdapter(mAdapter);
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
}
@Override

View File

@ -12,6 +12,7 @@ import android.widget.Spinner;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
/**
* 动画启动进入界面
@ -33,6 +34,10 @@ public class AnimationInActivity extends BaseActivity {
public void initView(View view) {
mAnimSp = (Spinner) findViewById(R.id.animation_sp);
mButton=(Button) findViewById(R.id.other_button);
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -5,6 +5,7 @@ import android.view.View;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
/**
* 动画启动退出界面
@ -21,7 +22,9 @@ public class AnimationOutActivity extends BaseActivity {
@Override
public void initView(View view) {
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -6,6 +6,7 @@ import android.widget.Button;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.tools.ToolLocation;
import com.zftlive.android.tools.ToolPhone;
@ -39,6 +40,10 @@ public class BasicTestActivity extends BaseActivity implements View.OnClickListe
btn_photo = (Button) findViewById(R.id.btn_photo);
btn_photo.setOnClickListener(this);
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -26,6 +26,7 @@ import android.widget.ImageView;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.tools.ToolAlert;
import com.zftlive.android.tools.ToolPicture;
@ -68,6 +69,10 @@ public class CameraPictureActivity extends BaseActivity {
takePic();
}
});
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -28,6 +28,7 @@ import android.widget.TextView;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.tools.ToolUnit;
/**
@ -116,6 +117,9 @@ public class LineChartActivity extends BaseActivity {
mUpRightTipView = LayoutInflater.from(this).inflate(R.layout.chat_tips_up_right, null);
tv_tips_ur = (TextView)mUpRightTipView.findViewById(R.id.tv_tips);
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -12,6 +12,7 @@ import android.widget.RelativeLayout;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.data.DTO;
import com.zftlive.android.model.Option;
import com.zftlive.android.tools.ToolAlert;
@ -56,6 +57,10 @@ public class AutoGainFormActivity extends BaseActivity {
SpinnerAdapter mSpinnerAdapter = new SpinnerAdapter(this, R.drawable.view_spinner_drop_list_hover, data);
mSpinnerAdapter.setDropDownViewResource(R.drawable.view_spinner_drop_list_ys);
sp_school.setAdapter(mSpinnerAdapter);
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}

View File

@ -22,6 +22,7 @@ import com.j256.ormlite.stmt.QueryBuilder;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.base.BaseAdapter;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.sample.db.entity.User;
import com.zftlive.android.tools.ToolAlert;
import com.zftlive.android.tools.ToolDatabase;
@ -67,6 +68,10 @@ public class DBDemoActivity extends BaseActivity {
btn_end_page = (Button) findViewById(R.id.btn_end_page);
lv_userlist = (ListView) findViewById(R.id.lv_userlist);
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -20,6 +20,7 @@ import android.widget.TextView;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.tools.ToolDateTime;
import com.zftlive.android.tools.ToolFile;
import com.zftlive.android.tools.ToolString;
@ -110,6 +111,10 @@ public class HVScorllListviewActivity extends BaseActivity {
//等待对话框
requestData(1);
mListView.getLoadingLayoutProxy().setLastUpdatedLabel("上次更新:"+ToolDateTime.formatDateTime(new Date(), "yyyy-MM-dd HH:mm"));
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -13,6 +13,7 @@ import android.widget.TextView;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.base.BaseAdapter;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.tools.ToolImage;
/**
@ -84,6 +85,10 @@ public class ImageListviewActivity extends BaseActivity {
//图片异步加载器
universalimageloader = ToolImage.initImageLoader(getApplicationContext());
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -11,6 +11,7 @@ import android.widget.TextView;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
/**
* 底部弹出泡泡选择菜单样例
@ -44,6 +45,10 @@ public class PopDialogMenuActivity extends BaseActivity {
popupWindow.showAtLocation(root, Gravity.BOTTOM, 0, 0);
}
});
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -9,6 +9,7 @@ import android.widget.Toast;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.view.progressbar.RoundProgressBar;
import com.zftlive.android.view.progressbar.VerticalProgressBar;
@ -43,6 +44,10 @@ public class ProgressBarActivity extends BaseActivity implements OnClickListener
btn_go = (Button)findViewById(R.id.btn_go);
btn_reset = (Button)findViewById(R.id.btn_reset);
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -14,6 +14,7 @@ import android.widget.EditText;
import com.zftlive.android.MApplication;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.tools.ToolAlert;
import com.zftlive.android.tools.ToolSMS;
import com.zftlive.android.tools.ToolString;
@ -47,6 +48,10 @@ public class PhoneValidateCodeActivity extends BaseActivity {
et_phone_code = (EditText)findViewById(R.id.et_phone_code);
btn_gain_smscode = (Button)findViewById(R.id.btn_gain_smscode);
btn_validate = (Button)findViewById(R.id.btn_validate);
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -12,6 +12,7 @@ import android.widget.EditText;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.tools.ToolAlert;
import com.zftlive.android.tools.ToolPhone;
import com.zftlive.android.tools.ToolString;
@ -42,6 +43,10 @@ public class SMSOperationActivity extends BaseActivity implements
btn_choice = (Button) findViewById(R.id.btn_choice);
btn_choice.setOnClickListener(this);
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -15,6 +15,7 @@ import android.widget.ListView;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.tools.ToolAlert;
import com.zftlive.android.tools.ToolSOAP;
@ -47,6 +48,10 @@ public class CityActivity extends BaseActivity {
getOperation().forward(WeatherActivity.class);
}
});
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -14,6 +14,7 @@ import android.widget.ListView;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.tools.ToolAlert;
import com.zftlive.android.tools.ToolSOAP;
@ -52,6 +53,9 @@ public class ProviceActivity extends BaseActivity {
}
});
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -10,6 +10,7 @@ import android.widget.TextView;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.tools.ToolAlert;
import com.zftlive.android.tools.ToolSOAP;
@ -31,6 +32,9 @@ public class WeatherActivity extends BaseActivity{
@Override
public void initView(View view) {
mTextWeather = (TextView) findViewById(R.id.weather);
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -10,6 +10,7 @@ import android.widget.ImageView;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.tools.ToolAlert;
import com.zftlive.android.tools.ToolFile;
import com.zftlive.android.tools.ToolPicture;
@ -41,6 +42,10 @@ public class ZxingGenBinActivity extends BaseActivity {
btn_make_bar = (Button)findViewById(R.id.btn_make_bar);
qr_image = (ImageView)findViewById(R.id.qr_image);
validate_image = (ImageView)findViewById(R.id.validate_image);
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override

View File

@ -6,6 +6,7 @@ import android.view.View;
import com.zftlive.android.R;
import com.zftlive.android.base.BaseActivity;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.zxing.CaptureActivity;
/**
@ -23,7 +24,9 @@ public class ZxingSacnnerActivity extends BaseActivity {
@Override
public void initView(View view) {
//初始化返回按钮
ActionBarManager.initActionBar(getApplicationContext(), getActionBar());
ActionBarManager.initBackTitle(getApplicationContext(),getActionBar());
}
@Override