<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="56dp" android:layout_alignParentBottom="true" android:orientation="horizontal" android:background="#27282c" > <RelativeLayout android:id="@+id/rl_1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginTop="4dp" android:layout_weight="1"> <RadioButton android:id="@+id/rb_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:button="@null" android:background="@null" android:checked="true" android:clickable="false" android:drawablePadding="5dp" android:drawableTop="@drawable/selector_tab_home" android:gravity="center" android:text="首页" android:textColor="@drawable/tab_text_selector" android:textSize="10sp" /> <TextView android:id="@+id/tv_1" android:layout_width="16dp" android:layout_height="16dp" android:layout_alignRight="@id/rb_1" android:layout_alignTop="@id/rb_1" android:layout_marginTop="-6dp" android:layout_marginRight="-6dp" android:layout_gravity="right" android:background="@drawable/msg_num_shape" android:clickable="false" android:gravity="center" android:text="3" android:textColor="@color/white_1" android:textSize="10sp" /> </RelativeLayout> <RelativeLayout android:id="@+id/rl_2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginTop="4dp" android:layout_weight="1" android:focusable="true"> <RadioButton android:id="@+id/rb_2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@null" android:button="@null" android:clickable="false" android:drawablePadding="5dp" android:drawableTop="@drawable/selector_tab_goods_divide" android:gravity="center" android:text="商品" android:textColor="@drawable/tab_text_selector" android:textSize="10sp" /> <TextView android:id="@+id/tv_2" android:layout_width="16dp" android:layout_height="16dp" android:layout_alignRight="@id/rb_2" android:layout_alignTop="@id/rb_2" android:layout_marginTop="-6dp" android:layout_marginRight="-6dp" android:layout_gravity="right" android:background="@drawable/msg_num_shape" android:clickable="false" android:gravity="center" android:text="3" android:textColor="@color/white_1" android:textSize="10sp" /> </RelativeLayout> <RelativeLayout android:id="@+id/rl_3" android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginTop="4dp" android:layout_weight="1"> <RadioButton android:id="@+id/rb_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@null" android:button="@null" android:clickable="false" android:drawablePadding="5dp" android:drawableTop="@drawable/selector_tab_stock_list" android:gravity="center" android:text="进货单" android:textColor="@drawable/tab_text_selector" android:textSize="10sp" /> <TextView android:id="@+id/tv_3" android:layout_width="16dp" android:layout_height="16dp" android:layout_alignRight="@id/rb_3" android:layout_alignTop="@id/rb_3" android:layout_marginTop="-6dp" android:layout_gravity="right" android:background="@drawable/msg_num_shape" android:clickable="false" android:gravity="center" android:text="3" android:textColor="@color/white_1" android:textSize="10sp" /> </RelativeLayout> <RelativeLayout android:id="@+id/rl_4" android:layout_width="0dp" android:layout_height="match_parent" android:layout_marginTop="4dp" android:layout_weight="1"> <RadioButton android:id="@+id/rb_4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@null" android:button="@null" android:clickable="false" android:drawablePadding="5dp" android:drawableTop="@drawable/selector_tab_member" android:gravity="center" android:text="会员" android:textColor="@drawable/tab_text_selector" android:textSize="10sp" /> <TextView android:id="@+id/tv_4" android:layout_width="16dp" android:layout_height="16dp" android:layout_alignRight="@id/rb_4" android:layout_alignTop="@id/rb_4" android:layout_marginTop="-6dp" android:layout_marginRight="-6dp" android:layout_gravity="right" android:background="@drawable/msg_num_shape" android:clickable="false" android:gravity="center" android:text="3" android:textColor="@color/white_1" android:textSize="10sp" /> </RelativeLayout> </LinearLayout>
/**
* -1:表示没有新消息
* -2:表示新消息用红点的方式显示
* 0-99:直接显示数字
* >=100:用99+显示
*/
private void messageTips(int num, TextView tv) {
if(num==-1){
tv.setVisibility(View.GONE);
}else if(num==-2){
tv.setVisibility(View.VISIBLE);
tv.setText("");
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) tv.getLayoutParams();
layoutParams.height= DensityUtil.dip2px(this,10);
layoutParams.width= DensityUtil.dip2px(this,10);
tv.setLayoutParams(layoutParams);
}else if(num>=0&&num<=99){
tv.setVisibility(View.VISIBLE);
tv.setText(num+"");
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) tv.getLayoutParams();
layoutParams.height= DensityUtil.dip2px(this,16);
layoutParams.width= DensityUtil.dip2px(this,16);
tv.setLayoutParams(layoutParams);
}else if(num>=100){
tv.setVisibility(View.VISIBLE);
tv.setText("99+");
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) tv.getLayoutParams();
layoutParams.height= DensityUtil.dip2px(this,16);
layoutParams.width= DensityUtil.dip2px(this,16);
tv.setTextSize(DensityUtil.sp2px(this,3));
tv.setLayoutParams(layoutParams);
}else{
tv.setVisibility(View.GONE);
}
}
/**
* 在oneFragment中更新,底部导航栏的数字
* @param num
*/
public void updateOne(int num){
messageTips(num,tv_1);
}
/**
* 在TwoFragment中更新,底部导航栏的数字
* @param num
*/
public void updateTwo(int num){
messageTips(num,tv_2);
}
/**
* 在ThreeFragment中更新,底部导航栏的数字
* @param num
*/
public void updateThree(int num){
messageTips(num,tv_3);
}
/**
* 在FourFragment中更新,底部导航栏的数字
* @param num
*/
public void updateFour(int num){
messageTips(num,tv_4);
}
mActivity = (MainActivity) getActivity(); number++; mActivity.updateTwo(number);
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_base" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.hrobbie.loadingproject.activity.BaseActivity"> <android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/tool_bar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:contentInsetStart="0.0dp" android:background="@color/colorPrimary" app:layout_scrollFlags="enterAlways|scroll" app:popupTheme="@style/AppTheme.PopupOverlay" /> <FrameLayout android:id="@+id/fl_content" android:layout_width="match_parent" android:layout_height="match_parent"> <include layout="@layout/loading_anim"/> </FrameLayout> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <!--加载中--> <LinearLayout android:id="@+id/ll_loading" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="90dp" android:gravity="center" android:orientation="vertical" > <ImageView android:id="@+id/iv_loading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/loading_everyday" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:text="正在为您开启干货推荐.." android:textColor="@color/colorTitle" android:textSize="14sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="7dp" android:text="看的越多,推荐越准" android:textColor="@color/colorSubtitle" android:textSize="12sp" android:visibility="visible" /> </LinearLayout> <!--加载失败--> <LinearLayout android:id="@+id/ll_error_refresh" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" android:visibility="gone"> <ImageView android:id="@+id/img_err" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/load_err" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:text="加载失败,点击重试" android:textSize="15sp" /> </LinearLayout> <!--加载失败--> <LinearLayout android:id="@+id/ll_no_data" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" android:visibility="gone"> <ImageView android:id="@+id/img_no_data" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/load_err" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:text="sorry,没有您想要的数据" android:textSize="15sp" /> </LinearLayout> </FrameLayout>
@Override
public void setContentView(@LayoutRes int layoutResID) {
View rootView = LayoutInflater.from(this).inflate(R.layout.activity_base,null,false);
addView = LayoutInflater.from(this).inflate(layoutResID, null, false);
//content
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
addView.setLayoutParams(params);
fl_content = (FrameLayout) rootView.findViewById(R.id.fl_content);
fl_content.addView(addView);
getWindow().setContentView(rootView);
initView();
showLoading();
}
vp_main.setOffscreenPageLimit(3);//最好是一屏能显示的fragment数-1。
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (getUserVisibleHint()){
isVisible=true;
onVisible();
}else {
isVisible=false;
onInvisible();
}
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mActivity= (MainActivity) getActivity();
showLoading();
lazyLoad();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有