Skip to content

Commit

Permalink
#update Toolbar 默认17sp
Browse files Browse the repository at this point in the history
  • Loading branch information
wumeng1 authored and wumeng1 committed Jul 16, 2021
1 parent 5099479 commit 0e5cafd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
5 changes: 3 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:showLine="true"
android:background="#FFFFFF"
app:title="@string/app_name" />
app:showLine="true"
app:title="@string/app_name"
app:titleTextSize="18sp" />

<com.mirkowu.lib_widget.NoScrollViewPager
android:id="@+id/vp_home"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@

import java.io.File;

/**
* 图片加载器
* 支持自定义加载库
*/
public class ImageLoader {

private volatile static ILoader sILoader;

private ImageLoader() {
}

/**
* 设置加载引擎
*
Expand All @@ -30,6 +37,7 @@ public static void setLoader(ILoader loader) {

/**
* 默认用 Glide
*
* @return
*/
public static ILoader getLoader() {
Expand Down
40 changes: 25 additions & 15 deletions lib_widget/src/main/java/com/mirkowu/lib_widget/Toolbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
Expand Down Expand Up @@ -35,6 +36,7 @@ public class Toolbar extends RelativeLayout {
private View vLine;
private boolean mShowLine;
private int mTitleColorId;
private int mTitleTextSize;
private int mRightColorId;
private Drawable mBackIconDrawable;
private Drawable mCloseIconDrawable;
Expand All @@ -60,6 +62,8 @@ private void init(Context context, AttributeSet attrs) {
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.Toolbar);
String title = ta.getString(R.styleable.Toolbar_title);
mTitleColorId = ta.getColor(R.styleable.Toolbar_titleColor, Color.parseColor("#222222"));
mTitleTextSize = ta.getDimensionPixelSize(R.styleable.Toolbar_titleTextSize, SizeUtils.dp2px(17f));
// int mTextSizeUnit = ta.peekValue(R.styleable.Toolbar_titleTextSize).getComplexUnit();
mRightColorId = ta.getColor(R.styleable.Toolbar_rightColor, Color.parseColor("#333333"));
mBackIconDrawable = ta.getDrawable(R.styleable.Toolbar_backIcon);
mCloseIconDrawable = ta.getDrawable(R.styleable.Toolbar_closeIcon);
Expand All @@ -77,6 +81,7 @@ private void init(Context context, AttributeSet attrs) {

setTitle(title);
setTitleColor(mTitleColorId);
setTitleTextSize(TypedValue.COMPLEX_UNIT_PX, mTitleTextSize);
setRightTextColor(mRightColorId);
setBackIcon(mBackIconDrawable);
setCloseIcon(mCloseIconDrawable);
Expand All @@ -103,6 +108,26 @@ public Toolbar setTitle(String title) {
return this;
}


public Toolbar setTitle(@StringRes int titleResId) {
tvTitle.setText(titleResId);
return this;
}

public Toolbar setTitleColor(@ColorInt int colorId) {
tvTitle.setTextColor(colorId);
return this;
}

public Toolbar setTitleTextSize(int sizeSp) {
return setTitleTextSize(TypedValue.COMPLEX_UNIT_SP, sizeSp);
}

public Toolbar setTitleTextSize(int unit, float size) {
tvTitle.setTextSize(unit, size);
return this;
}

/**
* 设置标题缩略格式 或 跑马灯
*
Expand All @@ -120,21 +145,6 @@ public Toolbar setTitleEllipsize(TextUtils.TruncateAt where) {
return this;
}

public Toolbar setTitle(@StringRes int titleResId) {
tvTitle.setText(titleResId);
return this;
}

public Toolbar setTitleColor(@ColorInt int colorId) {
tvTitle.setTextColor(colorId);
return this;
}

public Toolbar setTitleSize(int sizeSp) {
tvTitle.setTextSize(sizeSp);
return this;
}

public Toolbar setShowBackIcon(boolean isShow) {
if (isShow) {
setBackIcon(mBackIconDrawable);
Expand Down
2 changes: 1 addition & 1 deletion lib_widget/src/main/res/layout/widget_layout_toolbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
android:gravity="center"
android:singleLine="true"
android:textColor="#222222"
android:textSize="16sp"
android:textSize="17sp"
tools:text="标题" />


Expand Down
1 change: 1 addition & 0 deletions lib_widget/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<declare-styleable name="Toolbar">
<attr name="title" format="string" />
<attr name="titleColor" format="color" />
<attr name="titleTextSize" format="dimension" />
<attr name="titleEllipsize" format="enum">
<enum name="start" value="0" />
<enum name="middle" value="1" />
Expand Down

0 comments on commit 0e5cafd

Please sign in to comment.