使用自定义布局标题栏替代ActionBar,增加低版本兼容性
This commit is contained in:
parent
65d66ce82a
commit
bb9b23e75c
|
@ -157,7 +157,7 @@
|
|||
android:allowBackup="false"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppNotTransparentTheme" >
|
||||
android:theme="@android:style/Theme.Holo.Light.NoActionBar" >
|
||||
|
||||
<!-- 在本应用中导入需要使用的包,放在application里面activity外面 -->
|
||||
<uses-library android:name="android.test.runner" />
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 众筹详情界面标题栏黑色[返回]按钮选择器 -->
|
||||
<!-- 共通机能-标题栏黑色[返回]按钮选择器 -->
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/common_nav_back_black_n" android:state_focused="true" android:state_pressed="false"/>
|
||||
<item android:drawable="@drawable/common_nav_back_black_p" android:state_focused="true" android:state_pressed="true"/>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 众筹详情界面标题栏白色[返回]按钮选择器 -->
|
||||
<!-- 共通机能-标题栏白色[返回]按钮选择器 -->
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/common_nav_back_white_n" android:state_focused="true" android:state_pressed="false"/>
|
||||
<item android:drawable="@drawable/common_nav_back_white_p" android:state_focused="true" android:state_pressed="true"/>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 共通机能-蓝色按钮选择器 -->
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/shape_common_blue_btn_n" />
|
||||
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/shape_common_blue_btn_p" />
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 共通机能-按下背景5%透明度按钮选择器 [按下]+[普通]状态-->
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@color/black_05_alpha" android:state_pressed="true"/>
|
||||
<item android:drawable="@color/transparent" />
|
||||
</selector>
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Activity基类布局容器 -->
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<!-- 标题栏 -->
|
||||
|
||||
<include
|
||||
android:id="@+id/ll_title"
|
||||
layout="@layout/common_title_bar" />
|
||||
|
||||
<!-- 内容区域 -->
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fl_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/ll_title" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -42,27 +42,27 @@
|
|||
android:background="@android:color/transparent"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/common_share" />
|
||||
|
||||
<!-- 进度条 -->
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/pb_web_load_progress"
|
||||
style="@style/ProgressBar_Mini"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_gravity="center"
|
||||
android:max="100"
|
||||
android:progress="0" />
|
||||
</RelativeLayout>
|
||||
|
||||
<!-- 进度条 -->
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/pb_web_load_progress"
|
||||
style="@style/ProgressBar_Mini"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="4dp"
|
||||
android:layout_below="@+id/rl_webview_title_bar"
|
||||
android:layout_gravity="center"
|
||||
android:max="100"
|
||||
android:progress="0" />
|
||||
|
||||
<!-- webview容器(loading等待 + 错误提示重新加载 + webview) -->
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/rl_webview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/pb_web_load_progress" >
|
||||
android:layout_below="@+id/rl_webview_title_bar" >
|
||||
|
||||
<WebView
|
||||
android:id="@+id/webview"
|
||||
|
@ -76,8 +76,8 @@
|
|||
android:layout_height="match_parent"
|
||||
android:background="@color/error_bg"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"
|
||||
android:orientation="vertical" >
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone" >
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -15,15 +15,28 @@
|
|||
android:gravity="left|center_vertical"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<!-- 菜单按钮 -->
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/iv_menu"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/selector_common_transparent_btn"
|
||||
android:contentDescription="@null"
|
||||
android:scaleType="center"
|
||||
android:visibility="gone"
|
||||
android:src="@drawable/ic_list_white_48dp" />
|
||||
|
||||
<!-- 返回按钮 -->
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/iv_back"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="@android:color/transparent"
|
||||
android:background="@drawable/selector_common_transparent_btn"
|
||||
android:contentDescription="@null"
|
||||
android:scaleType="center"
|
||||
android:visibility="invisible"
|
||||
android:src="@drawable/selector_common_back_white_btn" />
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -38,9 +51,8 @@
|
|||
android:layout_toRightOf="@+id/ll_left_btns"
|
||||
android:ellipsize="end"
|
||||
android:gravity="left|center_vertical"
|
||||
android:maxLength="20"
|
||||
android:singleLine="true"
|
||||
android:text="标题栏"
|
||||
android:text=""
|
||||
android:textColor="@color/white"
|
||||
android:textSize="20sp" />
|
||||
|
||||
|
@ -61,7 +73,7 @@
|
|||
android:layout_width="50dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/selector_common_fav_white_btn"
|
||||
android:button="@null"
|
||||
android:button="@drawable/selector_common_transparent_btn"
|
||||
android:checked="false"
|
||||
android:textColor="#666666"
|
||||
android:textSize="16.67sp"
|
||||
|
@ -73,7 +85,7 @@
|
|||
android:layout_width="50dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/selector_common_share_white_btn"
|
||||
android:button="@null"
|
||||
android:button="@drawable/selector_common_transparent_btn"
|
||||
android:checked="false"
|
||||
android:textColor="#666666"
|
||||
android:textSize="16.67sp"
|
||||
|
|
|
@ -148,4 +148,5 @@
|
|||
<color name="navy">#000080</color><!--海军色 -->
|
||||
<color name="black">#000000</color><!--黑色 -->
|
||||
<color name="black_alpha">#70000000</color><!--黑色 -->
|
||||
<color name="black_05_alpha">#0C000000</color><!--5%黑色 -->
|
||||
</resources>
|
||||
|
|
|
@ -36,6 +36,9 @@ public class Launcher extends BaseActivity {
|
|||
@Override
|
||||
public void initView(View view) {
|
||||
|
||||
//隐藏标题栏
|
||||
hiddeTitleBar();
|
||||
|
||||
//添加动画效果
|
||||
AlphaAnimation animation = new AlphaAnimation(0.3f, 1.0f);
|
||||
animation.setDuration(2000);
|
||||
|
|
|
@ -51,7 +51,8 @@ public class FeedbackActivity extends BaseActivity{
|
|||
|
||||
//初始化返回按钮
|
||||
String strCenterTitle = getResources().getString(R.string.FeedbackActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -47,10 +47,13 @@ public class GuideActivity extends BaseActivity {
|
|||
public void run() {
|
||||
finish();
|
||||
}
|
||||
}, 2000);
|
||||
}, 300);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//隐藏标题栏
|
||||
hiddeTitleBar();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,16 +9,18 @@ import android.content.Context;
|
|||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.zftlive.android.library.MApplication;
|
||||
import com.zftlive.android.library.tools.ToolResource;
|
||||
import com.zftlive.android.library.widget.SwipeBackLayout;
|
||||
|
||||
/**
|
||||
|
@ -35,7 +37,7 @@ public abstract class BaseActivity extends FragmentActivity implements IBaseActi
|
|||
/** 当前Activity的弱引用,防止内存泄露 **/
|
||||
private WeakReference<Activity> context = null;
|
||||
/** 当前Activity渲染的视图View **/
|
||||
private View mContextView = null;
|
||||
private ViewGroup mContextView = null;
|
||||
/** 动画类型 **/
|
||||
private int mAnimationType = NONE;
|
||||
/** 是否运行截屏 **/
|
||||
|
@ -54,7 +56,12 @@ public abstract class BaseActivity extends FragmentActivity implements IBaseActi
|
|||
|
||||
// 获取应用Application
|
||||
mApplication = (MApplication) getApplicationContext();
|
||||
|
||||
|
||||
// 设置渲染视图View
|
||||
int baseLayout = BaseView.gainResId(mApplication, BaseView.LAYOUT, "activity_base_container");
|
||||
mContextView = (ViewGroup)LayoutInflater.from(this).inflate(baseLayout, null);
|
||||
setContentView(mContextView);
|
||||
|
||||
// 将当前Activity压入栈
|
||||
context = new WeakReference<Activity>(this);
|
||||
mApplication.pushTask(context);
|
||||
|
@ -70,15 +77,13 @@ public abstract class BaseActivity extends FragmentActivity implements IBaseActi
|
|||
bundle = new Bundle();
|
||||
}
|
||||
initParms(bundle);
|
||||
|
||||
// 设置渲染视图View
|
||||
|
||||
View mView = bindView();
|
||||
if (null == mView) {
|
||||
mContextView = LayoutInflater.from(this).inflate(bindLayout(), null);
|
||||
} else {
|
||||
mContextView = mView;
|
||||
mView = LayoutInflater.from(this).inflate(bindLayout(), null);
|
||||
}
|
||||
setContentView(mContextView);
|
||||
ViewGroup mContent = (ViewGroup) findViewById(BaseView.gainResId(mApplication, BaseView.ID, "fl_content"));
|
||||
mContent.addView(mView);
|
||||
|
||||
// 初始化控件
|
||||
initView(mContextView);
|
||||
|
@ -99,7 +104,7 @@ public abstract class BaseActivity extends FragmentActivity implements IBaseActi
|
|||
public View bindView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onRestart() {
|
||||
super.onRestart();
|
||||
|
@ -118,6 +123,11 @@ public abstract class BaseActivity extends FragmentActivity implements IBaseActi
|
|||
Log.d(TAG, "BaseActivity-->onResume()");
|
||||
resume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
|
@ -140,6 +150,11 @@ public abstract class BaseActivity extends FragmentActivity implements IBaseActi
|
|||
mApplication.removeTask(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示Actionbar菜单图标
|
||||
*/
|
||||
|
@ -205,6 +220,76 @@ public abstract class BaseActivity extends FragmentActivity implements IBaseActi
|
|||
this.isCanScreenshot = isCanScreenshot;
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏标题栏
|
||||
*/
|
||||
public void hiddeTitleBar(){
|
||||
//标题栏容器
|
||||
View mTitleBarContainer = findViewById(BaseView.gainResId(mApplication, BaseView.ID, "ll_title"));
|
||||
if(null == mTitleBarContainer){
|
||||
return;
|
||||
}
|
||||
mTitleBarContainer.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化返回按钮+标题左对齐
|
||||
* @param strTitle 标题名称
|
||||
* @param mBtnClickListener Home/Menu按钮点击监听事件
|
||||
*/
|
||||
public void initHomeMenuTitleBar(String strTitle,View.OnClickListener mBtnClickListener){
|
||||
View mMenuBtn = findViewById(BaseView.gainResId(mApplication, BaseView.ID, "iv_menu"));
|
||||
mMenuBtn.setVisibility(View.VISIBLE);
|
||||
if(null != mBtnClickListener){
|
||||
mMenuBtn.setOnClickListener(mBtnClickListener);
|
||||
}
|
||||
View mBackBtn = findViewById(BaseView.gainResId(mApplication, BaseView.ID, "iv_back"));
|
||||
mBackBtn.setVisibility(View.GONE);
|
||||
|
||||
//标题
|
||||
TextView mTitleText = (TextView)findViewById(BaseView.gainResId(mApplication, BaseView.ID, "tv_title"));
|
||||
mTitleText.setText(strTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化返回按钮+标题左对齐
|
||||
* @param strTitle 标题名称
|
||||
*/
|
||||
public void initBackTitleBar(String strTitle){
|
||||
initBackTitleBar(strTitle,Gravity.LEFT|Gravity.CENTER_VERTICAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化返回按钮+指定标题文本对齐方式
|
||||
* @param strTitle 标题名称
|
||||
* @param mGravity 标题文本对其方式 Gravity.LEFT|Gravity.CENTER_VERTICAL
|
||||
*/
|
||||
public void initBackTitleBar(String strTitle,int mGravity){
|
||||
//设置标题
|
||||
TextView mTitleText = (TextView)findViewById(BaseView.gainResId(mApplication, BaseView.ID, "tv_title"));
|
||||
mTitleText.setText(strTitle);
|
||||
mTitleText.setGravity(mGravity);
|
||||
|
||||
//设置点击事件
|
||||
View mBackBtn = findViewById(BaseView.gainResId(mApplication, BaseView.ID, "iv_back"));
|
||||
mBackBtn.setVisibility(View.VISIBLE);
|
||||
mBackBtn.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取标题栏容器,可以自行控制左右按钮和布局
|
||||
* @return
|
||||
*/
|
||||
public ViewGroup gainTitleBarVG(){
|
||||
return (ViewGroup)findViewById(BaseView.gainResId(mApplication, BaseView.ID, "ll_title"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Actionbar点击返回键关闭事件
|
||||
*/
|
||||
|
@ -227,13 +312,16 @@ public abstract class BaseActivity extends FragmentActivity implements IBaseActi
|
|||
super.finish();
|
||||
switch (mAnimationType) {
|
||||
case IBaseActivity.LEFT_RIGHT:
|
||||
overridePendingTransition(0, BaseView.gainResId(mApplication, BaseView.ANIM, "base_slide_right_out"));
|
||||
overridePendingTransition(0,
|
||||
BaseView.gainResId(mApplication, BaseView.ANIM, "base_slide_right_out"));
|
||||
break;
|
||||
case IBaseActivity.TOP_BOTTOM:
|
||||
overridePendingTransition(0, BaseView.gainResId(mApplication, BaseView.ANIM, "base_push_up_out"));
|
||||
overridePendingTransition(0,
|
||||
BaseView.gainResId(mApplication, BaseView.ANIM, "base_push_up_out"));
|
||||
break;
|
||||
case IBaseActivity.FADE_IN_OUT:
|
||||
overridePendingTransition(0, BaseView.gainResId(mApplication, BaseView.ANIM, "base_fade_out"));
|
||||
overridePendingTransition(0,
|
||||
BaseView.gainResId(mApplication, BaseView.ANIM, "base_fade_out"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.zftlive.android.library.common;
|
||||
|
||||
import com.zftlive.android.R;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.ActionBar.LayoutParams;
|
||||
import android.content.Context;
|
||||
|
@ -10,107 +12,121 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.zftlive.android.R;
|
||||
|
||||
/**
|
||||
* ActionBar管理器
|
||||
*
|
||||
* @author 曾繁添
|
||||
* @version 1.0
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ActionBarManager {
|
||||
|
||||
/**
|
||||
* 设置居中标题
|
||||
* @param mContext 上下文
|
||||
* @param actionBar actionbar
|
||||
* @param strCenterTitle 中间居中显示标题
|
||||
*/
|
||||
public static void initTitleCenterActionBar(Context mContext,ActionBar actionBar,String strCenterTitle){
|
||||
LayoutInflater inflator = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View centerTitle = inflator.inflate(R.layout.view_actionbar_title, null);
|
||||
TextView title = (TextView) centerTitle.findViewById(R.id.actionbar_title);
|
||||
title.setText(strCenterTitle);
|
||||
ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
|
||||
|
||||
actionBar.setDisplayShowCustomEnabled(true);
|
||||
actionBar.setCustomView(centerTitle,layoutParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新ActionBar中间标题
|
||||
* @param mContext 上下文
|
||||
* @param actionBar actionbar
|
||||
* @param strCenterTitle 中间居中显示标题
|
||||
*/
|
||||
public static void updateActionCenterTitle(Context mContext,ActionBar actionBar,String strCenterTitle){
|
||||
((TextView)actionBar.getCustomView().findViewById(R.id.actionbar_title)).setText(strCenterTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订制一个返回+标题的标题栏
|
||||
* @param mContext
|
||||
* @param actionBar
|
||||
* @param strCenterTitle
|
||||
*/
|
||||
public static void initMenuListTitle(Context mContext,ActionBar actionBar,String strCenterTitle){
|
||||
actionBar.setDisplayHomeAsUpEnabled(false);
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
actionBar.setDisplayShowTitleEnabled(false);
|
||||
actionBar.setHomeButtonEnabled(false);
|
||||
actionBar.setLogo(R.drawable.ic_list_white_48dp);
|
||||
actionBar.setDisplayUseLogoEnabled(true);
|
||||
initTitleCenterActionBar(mContext,actionBar,strCenterTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订制一个返回+标题的标题栏
|
||||
* @param mContext
|
||||
* @param actionBar
|
||||
* @param strCenterTitle
|
||||
*/
|
||||
public static void initBackTitle(Context mContext,ActionBar actionBar,String strCenterTitle){
|
||||
actionBar.setTitle("返回");
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(false);
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
initTitleCenterActionBar(mContext,actionBar,strCenterTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化【提交】右侧按钮菜单
|
||||
* @param mOptionsMenu
|
||||
*/
|
||||
public static void initActionBarSubmitButton(Menu mOptionsMenu){
|
||||
final MenuItem aboutItem = mOptionsMenu.findItem(R.id.action_about);
|
||||
if(null != aboutItem){
|
||||
aboutItem.setVisible(false);
|
||||
}
|
||||
|
||||
final MenuItem searchItem = mOptionsMenu.findItem(R.id.action_search);
|
||||
if(null != searchItem){
|
||||
searchItem.setVisible(false);
|
||||
}
|
||||
|
||||
final MenuItem favItem = mOptionsMenu.findItem(R.id.action_fav);
|
||||
if(null != favItem){
|
||||
favItem.setVisible(false);
|
||||
}
|
||||
|
||||
final MenuItem settingItem = mOptionsMenu.findItem(R.id.action_settings);
|
||||
if(null != settingItem){
|
||||
settingItem.setVisible(false);
|
||||
}
|
||||
|
||||
final MenuItem shareItem = mOptionsMenu.findItem(R.id.action_share);
|
||||
if(null != shareItem){
|
||||
shareItem.setVisible(false);
|
||||
}
|
||||
|
||||
final MenuItem submitItem = mOptionsMenu.findItem(R.id.action_submit);
|
||||
if(null != submitItem){
|
||||
submitItem.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置居中标题
|
||||
*
|
||||
* @param mContext 上下文
|
||||
* @param actionBar actionbar
|
||||
* @param strCenterTitle 中间居中显示标题
|
||||
*/
|
||||
public static void initTitleCenterActionBar(Context mContext, ActionBar actionBar,
|
||||
String strCenterTitle) {
|
||||
if (null == actionBar) return;
|
||||
LayoutInflater inflator =
|
||||
(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
View centerTitle = inflator.inflate(R.layout.view_actionbar_title, null);
|
||||
TextView title = (TextView) centerTitle.findViewById(R.id.actionbar_title);
|
||||
title.setText(strCenterTitle);
|
||||
ActionBar.LayoutParams layoutParams =
|
||||
new ActionBar.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
|
||||
|
||||
actionBar.setDisplayShowCustomEnabled(true);
|
||||
actionBar.setCustomView(centerTitle, layoutParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新ActionBar中间标题
|
||||
*
|
||||
* @param mContext 上下文
|
||||
* @param actionBar actionbar
|
||||
* @param strCenterTitle 中间居中显示标题
|
||||
*/
|
||||
public static void updateActionCenterTitle(Context mContext, ActionBar actionBar,
|
||||
String strCenterTitle) {
|
||||
if (null == actionBar) return;
|
||||
((TextView) actionBar.getCustomView().findViewById(R.id.actionbar_title))
|
||||
.setText(strCenterTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订制一个返回+标题的标题栏
|
||||
*
|
||||
* @param mContext
|
||||
* @param actionBar
|
||||
* @param strCenterTitle
|
||||
*/
|
||||
public static void initMenuListTitle(Context mContext, ActionBar actionBar, String strCenterTitle) {
|
||||
if (null == actionBar) return;
|
||||
actionBar.setDisplayHomeAsUpEnabled(false);
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
actionBar.setDisplayShowTitleEnabled(false);
|
||||
actionBar.setHomeButtonEnabled(false);
|
||||
actionBar.setLogo(R.drawable.ic_list_white_48dp);
|
||||
actionBar.setDisplayUseLogoEnabled(true);
|
||||
initTitleCenterActionBar(mContext, actionBar, strCenterTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订制一个返回+标题的标题栏
|
||||
*
|
||||
* @param mContext
|
||||
* @param actionBar
|
||||
* @param strCenterTitle
|
||||
*/
|
||||
public static void initBackTitle(Context mContext, ActionBar actionBar, String strCenterTitle) {
|
||||
if (null == actionBar) return;
|
||||
actionBar.setTitle("返回");
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(false);
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
initTitleCenterActionBar(mContext, actionBar, strCenterTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化【提交】右侧按钮菜单
|
||||
*
|
||||
* @param mOptionsMenu
|
||||
*/
|
||||
public static void initActionBarSubmitButton(Menu mOptionsMenu) {
|
||||
final MenuItem aboutItem = mOptionsMenu.findItem(R.id.action_about);
|
||||
if (null != aboutItem) {
|
||||
aboutItem.setVisible(false);
|
||||
}
|
||||
|
||||
final MenuItem searchItem = mOptionsMenu.findItem(R.id.action_search);
|
||||
if (null != searchItem) {
|
||||
searchItem.setVisible(false);
|
||||
}
|
||||
|
||||
final MenuItem favItem = mOptionsMenu.findItem(R.id.action_fav);
|
||||
if (null != favItem) {
|
||||
favItem.setVisible(false);
|
||||
}
|
||||
|
||||
final MenuItem settingItem = mOptionsMenu.findItem(R.id.action_settings);
|
||||
if (null != settingItem) {
|
||||
settingItem.setVisible(false);
|
||||
}
|
||||
|
||||
final MenuItem shareItem = mOptionsMenu.findItem(R.id.action_share);
|
||||
if (null != shareItem) {
|
||||
shareItem.setVisible(false);
|
||||
}
|
||||
|
||||
final MenuItem submitItem = mOptionsMenu.findItem(R.id.action_submit);
|
||||
if (null != submitItem) {
|
||||
submitItem.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,6 +163,9 @@ public class WebPageActivity extends BaseActivity implements
|
|||
ll_reload = (LinearLayout) findViewById(R.id.ll_reload);
|
||||
ll_reload.setOnClickListener(this);
|
||||
isError = false;
|
||||
|
||||
//隐藏标题栏
|
||||
hiddeTitleBar();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -84,7 +84,9 @@ public class MainActivity extends BaseActivity {
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.MainActivity);
|
||||
ActionBarManager.initMenuListTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initMenuListTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initHomeMenuTitleBar(strCenterTitle, null);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,7 +13,6 @@ import android.widget.Spinner;
|
|||
|
||||
import com.zftlive.android.R;
|
||||
import com.zftlive.android.library.base.BaseActivity;
|
||||
import com.zftlive.android.library.common.ActionBarManager;
|
||||
|
||||
/**
|
||||
* 动画启动进入界面
|
||||
|
@ -52,7 +51,8 @@ public class AnimationInActivity extends BaseActivity implements View.OnClickLis
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.AnimationInActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -41,7 +41,8 @@ public class AnimationOutActivity extends BaseActivity {
|
|||
public void initView(View view) {
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.AnimationInActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
|
||||
//追加右滑关闭activity顶层View
|
||||
rootView = (SwipeBackLayout) LayoutInflater.from(this).inflate(R.layout.view_swipeback_root, null);
|
||||
|
|
|
@ -42,7 +42,8 @@ public class AnimationOutPullActivity extends BaseActivity {
|
|||
public void initView(View view) {
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.AnimationInActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
|
||||
//追加右滑关闭activity顶层View
|
||||
rootView = (PullDownRemoveLayout) LayoutInflater.from(this).inflate(R.layout.view_pullback_root, null);
|
||||
|
|
|
@ -47,7 +47,8 @@ public class DialogEffectActivity extends BaseActivity {
|
|||
|
||||
// 初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.DialogEffectActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(),strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
public void dialogShow(View v) {
|
||||
|
|
|
@ -68,7 +68,8 @@ public class BasicTestActivity extends BaseActivity implements View.OnClickListe
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.BasicTestActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,8 @@ public class LoadHTMLActivity extends BaseActivity implements View.OnClickListen
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.LoadHTMLActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -83,7 +83,8 @@ public class CameraPictureActivity extends BaseActivity {
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.CameraPictureActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -131,7 +131,8 @@ public class LineChartActivity extends BaseActivity {
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.LineChartActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -73,7 +73,8 @@ public class AutoGainFormActivity extends BaseActivity {
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.AutoGainFormActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -84,7 +84,8 @@ public class DBDemoActivity extends BaseActivity {
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.DBDemoActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -128,7 +128,8 @@ public class HVScorllListviewActivity extends BaseActivity {
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.HVScorllListviewActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -109,7 +109,8 @@ public class SquareAutoFitGridviewActivity extends BaseActivity {
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.SquareAutoFitGridviewActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -77,7 +77,8 @@ public class FileDownloadUploadActivity extends BaseActivity implements OnClickL
|
|||
public void doBusiness(Context mContext) {
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.FileDownloadUploadActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -97,8 +97,8 @@ public class ImageListviewActivity extends BaseActivity {
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.ImageListviewActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -55,7 +55,8 @@ public class BaiduLocationActivity extends BaseActivity implements
|
|||
public void doBusiness(Context mContext) {
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.SquareAutoFitGridviewActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
|
||||
//请求定位
|
||||
ToolLocation.requestLocation(this, true);
|
||||
|
|
|
@ -74,7 +74,8 @@ public class DrawerLayoutActivity extends BaseActivity {
|
|||
actionBar.setLogo(R.drawable.ic_list_white_48dp);
|
||||
actionBar.setDisplayUseLogoEnabled(true);
|
||||
String strCenterTitle = getResources().getString(R.string.DrawerLayoutActivity);
|
||||
ActionBarManager.initTitleCenterActionBar(mContext,actionBar,strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -61,7 +61,8 @@ public class PopDialogMenuActivity extends BaseActivity {
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.PopDialogMenuActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -63,7 +63,8 @@ public class NumberPbActivity extends BaseActivity implements OnProgressBarListe
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.NumberPbActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -60,7 +60,8 @@ public class ProgressBarActivity extends BaseActivity implements OnClickListener
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.ProgressBarActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -44,7 +44,8 @@ public class StretchViewActivity extends BaseActivity {
|
|||
public void initView(View view) {
|
||||
mMainLayout = (TableLayout) findViewById(R.id.table_layout);
|
||||
//初始化带返回按钮的标题栏
|
||||
ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
|
||||
// ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
|
||||
initBackTitleBar(this.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -68,7 +68,8 @@ public class PhoneValidateCodeActivity extends BaseActivity {
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.PhoneValidateCodeActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -58,8 +58,8 @@ public class SMSOperationActivity extends BaseActivity implements
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.SMSOperationActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -63,7 +63,8 @@ public class CityActivity extends BaseActivity {
|
|||
});
|
||||
|
||||
//初始化带返回按钮的标题栏
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), "城市列表");
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), "城市列表");
|
||||
initBackTitleBar("城市列表");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -67,7 +67,8 @@ public class ProviceActivity extends BaseActivity {
|
|||
});
|
||||
|
||||
//初始化带返回按钮的标题栏
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), "省份列表");
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), "省份列表");
|
||||
initBackTitleBar("省份列表");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -46,7 +46,8 @@ public class WeatherActivity extends BaseActivity{
|
|||
public void initView(View view) {
|
||||
mTextWeather = (TextView) findViewById(R.id.weather);
|
||||
//初始化带返回按钮的标题栏
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), "天气信息");
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), "天气信息");
|
||||
initBackTitleBar("天气信息");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -58,7 +58,8 @@ public class ZxingGenBinActivity extends BaseActivity {
|
|||
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.ZxingGenBinActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,7 +39,8 @@ public class ZxingSacnnerActivity extends BaseActivity {
|
|||
public void initView(View view) {
|
||||
//初始化带返回按钮的标题栏
|
||||
String strCenterTitle = getResources().getString(R.string.ZxingSacnnerActivity);
|
||||
ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
// ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle);
|
||||
initBackTitleBar(strCenterTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue