|
|
@@ -8,6 +8,8 @@ import android.support.annotation.DrawableRes;
|
|
|
import android.support.design.widget.TabLayout;
|
|
|
import android.support.v4.app.Fragment;
|
|
|
import android.support.v4.view.ViewPager;
|
|
|
+import android.support.v7.app.ActionBar;
|
|
|
+import android.support.v7.app.AppCompatActivity;
|
|
|
import android.view.View;
|
|
|
import android.widget.Button;
|
|
|
import android.widget.ImageButton;
|
|
|
@@ -51,11 +53,12 @@ public class TitleBarUtils {
|
|
|
* @return
|
|
|
*/
|
|
|
public TitleBarUtils setTitle(Activity activity, String title) {
|
|
|
- TextView titleView = activity.findViewById(R.id.txt_baseactivity_title);
|
|
|
+ TextView titleView = activity.getWindow().getDecorView().findViewById(R.id.txt_baseactivity_title);
|
|
|
titleView.setVisibility(View.VISIBLE);
|
|
|
titleView.setText(title == null ? "" : title);
|
|
|
return mTitleBarUtils;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 设置标题
|
|
|
*
|
|
|
@@ -78,15 +81,16 @@ public class TitleBarUtils {
|
|
|
* @return
|
|
|
*/
|
|
|
public TitleBarUtils setTitleColor(Activity activity, int color) {
|
|
|
- TextView titleView = activity.findViewById(R.id.txt_baseactivity_title);
|
|
|
+ TextView titleView = activity.getWindow().getDecorView().findViewById(R.id.txt_baseactivity_title);
|
|
|
titleView.setTextColor(color);
|
|
|
return mTitleBarUtils;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 设置Title文本的颜色
|
|
|
*
|
|
|
* @param view
|
|
|
- * @param color 颜色值
|
|
|
+ * @param color 颜色值
|
|
|
* @return
|
|
|
*/
|
|
|
public TitleBarUtils setTitleColor(View view, int color) {
|
|
|
@@ -103,7 +107,7 @@ public class TitleBarUtils {
|
|
|
* @return
|
|
|
*/
|
|
|
public TitleBarUtils setTitleFinish(final Activity activity) {
|
|
|
- activity.findViewById(R.id.img_baseactivity_title)
|
|
|
+ activity.getWindow().getDecorView().findViewById(R.id.img_baseactivity_title)
|
|
|
.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
@@ -114,7 +118,7 @@ public class TitleBarUtils {
|
|
|
}
|
|
|
|
|
|
public TitleBarUtils setTitleBack(final Activity activity) {
|
|
|
- activity.findViewById(R.id.img_baseactivity_title)
|
|
|
+ activity.getWindow().getDecorView().findViewById(R.id.img_baseactivity_title)
|
|
|
.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
@@ -134,16 +138,19 @@ public class TitleBarUtils {
|
|
|
});
|
|
|
return mTitleBarUtils;
|
|
|
}
|
|
|
+
|
|
|
public TitleBarUtils setTitleFinish(final View view, View.OnClickListener listener) {
|
|
|
view.findViewById(R.id.img_baseactivity_title)
|
|
|
.setOnClickListener(listener);
|
|
|
return mTitleBarUtils;
|
|
|
}
|
|
|
+
|
|
|
public TitleBarUtils setTitleFinish(final Activity activity, View.OnClickListener listener) {
|
|
|
- activity.findViewById(R.id.img_baseactivity_title)
|
|
|
+ activity.getWindow().getDecorView().findViewById(R.id.img_baseactivity_title)
|
|
|
.setOnClickListener(listener);
|
|
|
return mTitleBarUtils;
|
|
|
}
|
|
|
+
|
|
|
public TitleBarUtils setTitleFinish(final Activity activity, View view) {
|
|
|
view.findViewById(R.id.img_baseactivity_title)
|
|
|
.setOnClickListener(new View.OnClickListener() {
|
|
|
@@ -157,6 +164,7 @@ public class TitleBarUtils {
|
|
|
|
|
|
public static final int GONE = -2;
|
|
|
public static final int INVISIBLE = 0;
|
|
|
+
|
|
|
/**
|
|
|
* 设置最左边的Title监听
|
|
|
*
|
|
|
@@ -165,7 +173,7 @@ public class TitleBarUtils {
|
|
|
* @param onClickListener 如果为null,不改监听
|
|
|
*/
|
|
|
public TitleBarUtils setTitleListen(Activity activity, int drawableID, View.OnClickListener onClickListener) {
|
|
|
- ImageView imageView = activity.findViewById(R.id.img_baseactivity_title);
|
|
|
+ ImageView imageView = activity.getWindow().getDecorView().findViewById(R.id.img_baseactivity_title);
|
|
|
switch (drawableID) {
|
|
|
case INVISIBLE:
|
|
|
imageView.setVisibility(View.INVISIBLE);
|
|
|
@@ -185,6 +193,7 @@ public class TitleBarUtils {
|
|
|
}
|
|
|
return mTitleBarUtils;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 设置最左边的Title监听
|
|
|
*
|
|
|
@@ -220,8 +229,8 @@ public class TitleBarUtils {
|
|
|
*/
|
|
|
public TitleBarUtils setRightBtn(Activity activity, String btnText, int backgroundColorResId,
|
|
|
View.OnClickListener onClickListener) {
|
|
|
- Button button = activity.findViewById(R.id.btn_baseactivity_right);
|
|
|
- ImageButton imageButton = activity.findViewById(R.id.ibtn_baseactivity_right);
|
|
|
+ Button button = activity.getWindow().getDecorView().findViewById(R.id.btn_baseactivity_right);
|
|
|
+ ImageButton imageButton = activity.getWindow().getDecorView().findViewById(R.id.ibtn_baseactivity_right);
|
|
|
button.setVisibility(View.VISIBLE);
|
|
|
imageButton.setVisibility(View.GONE);
|
|
|
if (backgroundColorResId == 0) {
|
|
|
@@ -242,6 +251,7 @@ public class TitleBarUtils {
|
|
|
}
|
|
|
return this;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 设置最右边的普通按钮状态
|
|
|
*
|
|
|
@@ -284,9 +294,9 @@ public class TitleBarUtils {
|
|
|
* @param onClickListener 点击时的操作。
|
|
|
*/
|
|
|
public TitleBarUtils setRightImgBotton(Activity activity, int backgroundImgResId, View.OnClickListener onClickListener) {
|
|
|
- Button button = activity.findViewById(R.id.btn_baseactivity_right);
|
|
|
- ImageButton imageButton = activity.findViewById(R.id.ibtn_baseactivity_right);
|
|
|
- if(button != null)
|
|
|
+ Button button = activity.getWindow().getDecorView().findViewById(R.id.btn_baseactivity_right);
|
|
|
+ ImageButton imageButton = activity.getWindow().getDecorView().findViewById(R.id.ibtn_baseactivity_right);
|
|
|
+ if (button != null)
|
|
|
button.setVisibility(View.GONE);
|
|
|
imageButton.setVisibility(View.VISIBLE);
|
|
|
if (backgroundImgResId == 0) {
|
|
|
@@ -302,6 +312,7 @@ public class TitleBarUtils {
|
|
|
}
|
|
|
return this;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 设置最右边的普通按钮状态
|
|
|
*
|
|
|
@@ -312,7 +323,7 @@ public class TitleBarUtils {
|
|
|
public TitleBarUtils setRightImgBotton(View view, int backgroundImgResId, View.OnClickListener onClickListener) {
|
|
|
Button button = view.findViewById(R.id.btn_baseactivity_right);
|
|
|
ImageButton imageButton = view.findViewById(R.id.ibtn_baseactivity_right);
|
|
|
- if(button != null)
|
|
|
+ if (button != null)
|
|
|
button.setVisibility(View.GONE);
|
|
|
imageButton.setVisibility(View.VISIBLE);
|
|
|
if (backgroundImgResId == 0) {
|
|
|
@@ -331,12 +342,13 @@ public class TitleBarUtils {
|
|
|
|
|
|
/**
|
|
|
* 设置红点是否显示
|
|
|
+ *
|
|
|
* @param activity
|
|
|
* @param visibility
|
|
|
*/
|
|
|
- public void setRightRedPoint(Activity activity, int visibility){
|
|
|
+ public void setRightRedPoint(Activity activity, int visibility) {
|
|
|
|
|
|
- activity.findViewById(R.id.img_download_manager_dots).setVisibility(visibility);
|
|
|
+ activity.getWindow().getDecorView().findViewById(R.id.img_download_manager_dots).setVisibility(visibility);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -355,7 +367,7 @@ public class TitleBarUtils {
|
|
|
* @param visibility
|
|
|
*/
|
|
|
public void setRightImgBtnVisibility(Activity activity, int visibility) {
|
|
|
- activity.findViewById(R.id.ibtn_baseactivity_right).setVisibility(visibility);
|
|
|
+ activity.getWindow().getDecorView().findViewById(R.id.ibtn_baseactivity_right).setVisibility(visibility);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -365,7 +377,7 @@ public class TitleBarUtils {
|
|
|
* @return
|
|
|
*/
|
|
|
public Button getRightBtn(Activity activity) {
|
|
|
- return (Button) activity.findViewById(R.id.btn_baseactivity_right);
|
|
|
+ return (Button) activity.getWindow().getDecorView().findViewById(R.id.btn_baseactivity_right);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -375,7 +387,7 @@ public class TitleBarUtils {
|
|
|
* @return
|
|
|
*/
|
|
|
public ImageButton getRightImgBtn(Activity activity) {
|
|
|
- return (ImageButton) activity.findViewById(R.id.ibtn_baseactivity_right);
|
|
|
+ return (ImageButton) activity.getWindow().getDecorView().findViewById(R.id.ibtn_baseactivity_right);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -383,8 +395,23 @@ public class TitleBarUtils {
|
|
|
* 隐藏标题栏所有组件,GONE或VISIBLE
|
|
|
*/
|
|
|
public TitleBarUtils setShowOrHide(Activity activity, boolean isShow) {
|
|
|
- activity.findViewById(R.id.layout_navigationBar)
|
|
|
- .setVisibility(isShow ? View.VISIBLE : View.GONE);
|
|
|
+ if (activity instanceof AppCompatActivity) {
|
|
|
+ AppCompatActivity aact = (AppCompatActivity) activity;
|
|
|
+ ActionBar actionBar = aact.getSupportActionBar();
|
|
|
+ if (actionBar != null) {
|
|
|
+ if (isShow) {
|
|
|
+ actionBar.show();
|
|
|
+ } else {
|
|
|
+ actionBar.hide();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ activity.getWindow().getDecorView().findViewById(R.id.layout_navigationBar)
|
|
|
+ .setVisibility(isShow ? View.VISIBLE : View.GONE);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ activity.getWindow().getDecorView().findViewById(R.id.layout_navigationBar)
|
|
|
+ .setVisibility(isShow ? View.VISIBLE : View.GONE);
|
|
|
+ }
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
@@ -393,10 +420,11 @@ public class TitleBarUtils {
|
|
|
* 隐藏线,GONE或VISIBLE
|
|
|
*/
|
|
|
public TitleBarUtils setShowOrHideLine(Activity activity, boolean isShow) {
|
|
|
- activity.findViewById(R.id.title_bottom_line)
|
|
|
+ activity.getWindow().getDecorView().findViewById(R.id.title_bottom_line)
|
|
|
.setVisibility(isShow ? View.VISIBLE : View.GONE);
|
|
|
return mTitleBarUtils;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 隐藏线,GONE或VISIBLE
|
|
|
*/
|
|
|
@@ -411,10 +439,11 @@ public class TitleBarUtils {
|
|
|
* 设置标题栏颜色
|
|
|
*/
|
|
|
public TitleBarUtils setTitleBackgroud(Activity activity, int backgroundImgResId) {
|
|
|
- activity.findViewById(R.id.layout_navigationBar)
|
|
|
+ activity.getWindow().getDecorView().findViewById(R.id.layout_navigationBar)
|
|
|
.setBackground(activity.getResources().getDrawable(backgroundImgResId));
|
|
|
return mTitleBarUtils;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 设置标题栏颜色
|
|
|
*/
|
|
|
@@ -427,8 +456,8 @@ public class TitleBarUtils {
|
|
|
/**
|
|
|
* 设置 从右边数,第两个按钮
|
|
|
*/
|
|
|
- public TitleBarUtils setRightSecondBtn(Activity activity, @DrawableRes int secondRes, View.OnClickListener secondOnclick){
|
|
|
- ImageButton secondImageButton = activity.findViewById(R.id.ibtn_two_right);
|
|
|
+ public TitleBarUtils setRightSecondBtn(Activity activity, @DrawableRes int secondRes, View.OnClickListener secondOnclick) {
|
|
|
+ ImageButton secondImageButton = activity.getWindow().getDecorView().findViewById(R.id.ibtn_two_right);
|
|
|
|
|
|
secondImageButton.setVisibility(View.VISIBLE);
|
|
|
secondImageButton.setImageResource(secondRes);
|
|
|
@@ -439,10 +468,10 @@ public class TitleBarUtils {
|
|
|
|
|
|
public TitleBarUtils addTabs(final BaseActivity activity, ViewPager viewPager, String tab1, Fragment fragment1, String tab2, Fragment fragment2, ViewPager.OnPageChangeListener listener) {
|
|
|
//设置标题不可见
|
|
|
- TextView titleView = activity.findViewById(R.id.txt_baseactivity_title);
|
|
|
+ TextView titleView = activity.getWindow().getDecorView().findViewById(R.id.txt_baseactivity_title);
|
|
|
titleView.setVisibility(View.GONE);
|
|
|
//设置tab可见
|
|
|
- TabLayout tabLayout = activity.findViewById(R.id.title_tab);
|
|
|
+ TabLayout tabLayout = activity.getWindow().getDecorView().findViewById(R.id.title_tab);
|
|
|
tabLayout.setVisibility(View.VISIBLE);
|
|
|
|
|
|
TitleFragmentListAdapter adapter = new TitleFragmentListAdapter(activity.getSupportFragmentManager());
|
|
|
@@ -458,10 +487,11 @@ public class TitleBarUtils {
|
|
|
// CommonUtil.getInstance().reflex(tabLayout, activity);
|
|
|
return this;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 设置 从右边数,第两个按钮
|
|
|
*/
|
|
|
- public TitleBarUtils setRightSecondBtn(View view, @DrawableRes int secondRes, View.OnClickListener secondOnclick){
|
|
|
+ public TitleBarUtils setRightSecondBtn(View view, @DrawableRes int secondRes, View.OnClickListener secondOnclick) {
|
|
|
ImageButton secondImageButton = view.findViewById(R.id.ibtn_two_right);
|
|
|
|
|
|
secondImageButton.setVisibility(View.VISIBLE);
|
|
|
@@ -470,6 +500,7 @@ public class TitleBarUtils {
|
|
|
secondImageButton.setOnClickListener(secondOnclick);
|
|
|
return this;
|
|
|
}
|
|
|
+
|
|
|
public TitleBarUtils addTabs(final BaseFragment baseFragment, ViewPager viewPager, String tab1, Fragment fragment1, String tab2, Fragment fragment2, ViewPager.OnPageChangeListener listener) {
|
|
|
//设置标题不可见
|
|
|
TextView titleView = baseFragment.findViewById(R.id.txt_baseactivity_title);
|
|
|
@@ -494,14 +525,14 @@ public class TitleBarUtils {
|
|
|
|
|
|
public TitleBarUtils addMsgTab(final BaseActivity activity, final ViewPager viewPager) {
|
|
|
//设置标题不可见
|
|
|
- TextView titleView = activity.findViewById(R.id.txt_baseactivity_title);
|
|
|
+ TextView titleView = activity.getWindow().getDecorView().findViewById(R.id.txt_baseactivity_title);
|
|
|
titleView.setVisibility(View.GONE);
|
|
|
//设置tab可见
|
|
|
- View msg_title_tab = activity.findViewById(R.id.msg_title_tab);
|
|
|
+ View msg_title_tab = activity.getWindow().getDecorView().findViewById(R.id.msg_title_tab);
|
|
|
msg_title_tab.setVisibility(View.VISIBLE);
|
|
|
final TextView[] textViews = new TextView[2];
|
|
|
- textViews[0] = activity.findViewById(R.id.title_tab_tv_0);
|
|
|
- textViews[1] = activity.findViewById(R.id.title_tab_tv_1);
|
|
|
+ textViews[0] = activity.getWindow().getDecorView().findViewById(R.id.title_tab_tv_0);
|
|
|
+ textViews[1] = activity.getWindow().getDecorView().findViewById(R.id.title_tab_tv_1);
|
|
|
textViews[0].setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
@@ -516,6 +547,7 @@ public class TitleBarUtils {
|
|
|
});
|
|
|
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
|
|
private int lastPosition = 0;
|
|
|
+
|
|
|
@Override
|
|
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|
|
|
|
|
@@ -543,15 +575,16 @@ public class TitleBarUtils {
|
|
|
|
|
|
/**
|
|
|
* 设置最后的textView的文本,颜色与点击事件
|
|
|
+ *
|
|
|
* @param activity
|
|
|
- * @param text 要显示的文本
|
|
|
- * @param color 要显示的颜色
|
|
|
+ * @param text 要显示的文本
|
|
|
+ * @param color 要显示的颜色
|
|
|
* @param onClickListener 点击事件
|
|
|
* @return
|
|
|
*/
|
|
|
public TitleBarUtils setEndTv(Activity activity, String text, int color, View.OnClickListener onClickListener) {
|
|
|
- TextView textView = activity.findViewById(R.id.title_end_tv);
|
|
|
- if(textView != null) {
|
|
|
+ TextView textView = activity.getWindow().getDecorView().findViewById(R.id.title_end_tv);
|
|
|
+ if (textView != null) {
|
|
|
textView.setVisibility(View.VISIBLE);
|
|
|
ViewUtil.setText(textView, text);
|
|
|
if (color > 0)
|