|
@@ -7,10 +7,18 @@ import android.support.v7.widget.Toolbar;
|
|
|
import android.util.AttributeSet;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
+import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.bumptech.glide.Glide;
|
|
|
import com.sheishuo.app.R;
|
|
|
+import com.sheishuo.app.common.util.img.ImgUtil;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import okhttp3.FormBody;
|
|
|
|
|
|
/**
|
|
|
* Created by KN on 2017/7/20.
|
|
@@ -19,12 +27,19 @@ import com.sheishuo.app.R;
|
|
|
public class BaseToolbar extends Toolbar {
|
|
|
|
|
|
private final String TITLE = "title",LEFT_TEXT = "left_text",RIGHT_TEXT = "right_text";
|
|
|
+ private static Context context;
|
|
|
private String titleStr = "",leftStr = "",rightStr = "";
|
|
|
private TextView titleTV,leftTV,rightTV;
|
|
|
+ private LinearLayout icoLayout;
|
|
|
+
|
|
|
+ public interface IcoBtnClickListener{
|
|
|
+ void onClick(View view);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
public BaseToolbar(Context context, @Nullable AttributeSet attrs) {
|
|
|
super(context, attrs);
|
|
|
+ this.context = context;
|
|
|
View view = LayoutInflater.from(context).inflate(R.layout.base_toolbar,this,true);
|
|
|
findViews(view);
|
|
|
assert attrs != null;
|
|
@@ -56,6 +71,7 @@ public class BaseToolbar extends Toolbar {
|
|
|
titleTV = (TextView) view.findViewById(R.id.toolbar_title);
|
|
|
leftTV = (TextView) view.findViewById(R.id.toolbar_left);
|
|
|
rightTV = (TextView) view.findViewById(R.id.toolbar_right);
|
|
|
+ icoLayout = (LinearLayout) view.findViewById(R.id.toolbar_ico_layout);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -76,6 +92,8 @@ public class BaseToolbar extends Toolbar {
|
|
|
titleTV.setVisibility(INVISIBLE);
|
|
|
leftTV.setVisibility(INVISIBLE);
|
|
|
rightTV.setVisibility(INVISIBLE);
|
|
|
+ icoLayout.removeAllViews();
|
|
|
+ icoLayout.setVisibility(GONE);
|
|
|
titleTV.setOnClickListener(null);
|
|
|
leftTV.setOnClickListener(null);
|
|
|
rightTV.setOnClickListener(null);
|
|
@@ -84,6 +102,10 @@ public class BaseToolbar extends Toolbar {
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public void setTitle(String title){
|
|
|
getTitleTV().setText(title);
|
|
|
titleTV.setVisibility(VISIBLE);
|
|
@@ -101,6 +123,81 @@ public class BaseToolbar extends Toolbar {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public LinearLayout getIcoLayout() {
|
|
|
+ return icoLayout;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setIcoLayout(LinearLayout icoLayout) {
|
|
|
+ this.icoLayout = icoLayout;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**************用于为BaseToolbar增加额外功能***************/
|
|
|
+
|
|
|
+
|
|
|
+ public static class Builder implements OnClickListener{
|
|
|
+
|
|
|
+ BaseToolbar toolbar;
|
|
|
+ private List<Integer> icoIds = new ArrayList<>();
|
|
|
+ IcoBtnClickListener listener;
|
|
|
+ Context context;
|
|
|
+
|
|
|
+ public Builder create(Context context,@Nullable BaseToolbar toolbar){
|
|
|
+ if (toolbar == null){
|
|
|
+ this.toolbar = new BaseToolbar(context,null);
|
|
|
+ }else {
|
|
|
+ this.toolbar = toolbar;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.context = context;
|
|
|
+
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 为Toolbar添加一个图标按钮
|
|
|
+ *
|
|
|
+ * 为了保证布局显示正常,若添加ico按钮则自动隐藏Right_Text
|
|
|
+ * @param resId
|
|
|
+ */
|
|
|
+ public BaseToolbar.Builder addIcoButton(int resId){
|
|
|
+ toolbar.rightTV.setVisibility(GONE);
|
|
|
+ toolbar.icoLayout.setVisibility(VISIBLE);
|
|
|
+ ImageView icoView = new ImageView(context);
|
|
|
+ icoView.setAdjustViewBounds(true);
|
|
|
+ int dpToPixel = (int) ImgUtil.convertDpToPixel(24,context);
|
|
|
+ Glide.with(context)
|
|
|
+ .load(resId)
|
|
|
+ .override(dpToPixel,dpToPixel)
|
|
|
+ .into(icoView);
|
|
|
+ toolbar.icoLayout.addView(icoView);
|
|
|
+ icoIds.add(resId);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public BaseToolbar.Builder addIcoButtonClickListener(int index,IcoBtnClickListener listener){
|
|
|
+ this.listener = listener;
|
|
|
+ toolbar.getIcoLayout().getChildAt(0).setOnClickListener(this);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public BaseToolbar build(){
|
|
|
+ return toolbar;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (listener != null) listener.onClick(v);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
|