Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

字体加粗bug #375

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions FlycoTabLayout_Lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'//添加
//apply plugin: 'com.github.dcendents.android-maven'
//apply plugin: 'com.jfrog.bintray'

// 这个version是区分library版本的,因此当我们需要更新library时记得修改这个version
version = "2.1.2"
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
compileSdkVersion 26

defaultConfig {
minSdkVersion 11
targetSdkVersion 25
targetSdkVersion 26
versionCode 212
versionName version
}
Expand All @@ -24,15 +24,43 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:25.1.0'
compile 'com.android.support:support-v4:26.1.0'
}




// 打包源码jar
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}


allprojects {
tasks.withType(Javadoc) {
options.encoding = "UTF-8"
}
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
options.encoding = "UTF-8"
}
publish {
artifactId = 'FlycoTabLayout_Lib' // library的名字
groupId = 'com.vclicai'// 包名
publishVersion = '1.1.2' // 版本
website = 'https://github.com/H07000223/FlycoTabLayout'
userOrg = 'vclicai'
}

//def siteUrl = 'https://github.com/H07000223' // 项目的主页
//def gitUrl = 'https://github.com/H07000223' // Git仓库的url
//group = "com.flyco.tablayout" // Maven Group ID for the artifact,一般填你唯一的包名
//install {
// repositories.mavenInstaller {
// // This generates POM.xml with proper parameters
// // This generate1 POM.xml with proper parameters
// pom {
// project {
// packaging 'aar'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@

import java.util.ArrayList;

/** 没有继承HorizontalScrollView不能滑动,对于ViewPager无依赖 */
/**
* 没有继承HorizontalScrollView不能滑动,对于ViewPager无依赖
*/
public class CommonTabLayout extends FrameLayout implements ValueAnimator.AnimatorUpdateListener {
private Context mContext;
private ArrayList<CustomTabEntity> mTabEntitys = new ArrayList<>();
private LinearLayout mTabsContainer;
private int mCurrentTab;
private int mLastTab;
private int mTabCount;
/** 用于绘制显示器 */
/**
* 用于绘制显示器
*/
private Rect mIndicatorRect = new Rect();
private GradientDrawable mIndicatorDrawable = new GradientDrawable();

Expand All @@ -59,7 +63,9 @@ public class CommonTabLayout extends FrameLayout implements ValueAnimator.Animat
private boolean mTabSpaceEqual;
private float mTabWidth;

/** indicator */
/**
* indicator
*/
private int mIndicatorColor;
private float mIndicatorHeight;
private float mIndicatorWidth;
Expand All @@ -73,27 +79,36 @@ public class CommonTabLayout extends FrameLayout implements ValueAnimator.Animat
private boolean mIndicatorBounceEnable;
private int mIndicatorGravity;

/** underline */
/**
* underline
*/
private int mUnderlineColor;
private float mUnderlineHeight;
private int mUnderlineGravity;

/** divider */
/**
* divider
*/
private int mDividerColor;
private float mDividerWidth;
private float mDividerPadding;

/** title */
/**
* title
*/
private static final int TEXT_BOLD_NONE = 0;
private static final int TEXT_BOLD_WHEN_SELECT = 1;
private static final int TEXT_BOLD_BOTH = 2;
private float mTextsize;
private float mTextSelectSize;
private int mTextSelectColor;
private int mTextUnselectColor;
private int mTextBold;
private boolean mTextAllCaps;

/** icon */
/**
* icon
*/
private boolean mIconVisible;
private int mIconGravity;
private float mIconWidth;
Expand All @@ -102,7 +117,9 @@ public class CommonTabLayout extends FrameLayout implements ValueAnimator.Animat

private int mHeight;

/** anim */
/**
* anim
*/
private ValueAnimator mValueAnimator;
private OvershootInterpolator mInterpolator = new OvershootInterpolator(1.5f);

Expand Down Expand Up @@ -172,6 +189,10 @@ private void obtainAttributes(Context context, AttributeSet attrs) {
mDividerPadding = ta.getDimension(R.styleable.CommonTabLayout_tl_divider_padding, dp2px(12));

mTextsize = ta.getDimension(R.styleable.CommonTabLayout_tl_textsize, sp2px(13f));
mTextSelectSize = ta.getDimension(R.styleable.CommonTabLayout_tl_textSelectSize, sp2px(0f));
if (mTextSelectSize == 0) {
mTextSelectSize = mTextsize;
}
mTextSelectColor = ta.getColor(R.styleable.CommonTabLayout_tl_textSelectColor, Color.parseColor("#ffffff"));
mTextUnselectColor = ta.getColor(R.styleable.CommonTabLayout_tl_textUnselectColor, Color.parseColor("#AAffffff"));
mTextBold = ta.getInt(R.styleable.CommonTabLayout_tl_textBold, TEXT_BOLD_NONE);
Expand Down Expand Up @@ -201,13 +222,17 @@ public void setTabData(ArrayList<CustomTabEntity> tabEntitys) {
notifyDataSetChanged();
}

/** 关联数据支持同时切换fragments */
/**
* 关联数据支持同时切换fragments
*/
public void setTabData(ArrayList<CustomTabEntity> tabEntitys, FragmentActivity fa, int containerViewId, ArrayList<Fragment> fragments) {
mFragmentChangeManager = new FragmentChangeManager(fa.getSupportFragmentManager(), containerViewId, fragments);
setTabData(tabEntitys);
}

/** 更新数据 */
/**
* 更新数据
*/
public void notifyDataSetChanged() {
mTabsContainer.removeAllViews();
this.mTabCount = mTabEntitys.size();
Expand All @@ -230,7 +255,9 @@ public void notifyDataSetChanged() {
updateTabStyles();
}

/** 创建并添加tab */
/**
* 创建并添加tab
*/
private void addTab(final int position, View tabView) {
TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
tv_tab_title.setText(mTabEntitys.get(position).getTabTitle());
Expand Down Expand Up @@ -270,7 +297,7 @@ private void updateTabStyles() {
tabView.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
tv_tab_title.setTextColor(i == mCurrentTab ? mTextSelectColor : mTextUnselectColor);
tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextsize);
tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, i == mCurrentTab ? mTextSelectSize : mTextsize);
// tv_tab_title.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
if (mTextAllCaps) {
tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase());
Expand All @@ -280,6 +307,8 @@ private void updateTabStyles() {
tv_tab_title.getPaint().setFakeBoldText(true);
} else if (mTextBold == TEXT_BOLD_NONE) {
tv_tab_title.getPaint().setFakeBoldText(false);
}else if (mTextBold ==TEXT_BOLD_WHEN_SELECT){
tv_tab_title.getPaint().setFakeBoldText(i == mCurrentTab);
}

ImageView iv_tab_icon = (ImageView) tabView.findViewById(R.id.iv_tab_icon);
Expand Down Expand Up @@ -313,6 +342,7 @@ private void updateTabSelection(int position) {
final boolean isSelect = i == position;
TextView tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
tab_title.setTextColor(isSelect ? mTextSelectColor : mTextUnselectColor);
tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, isSelect ? mTextSelectSize : mTextsize);
ImageView iv_tab_icon = (ImageView) tabView.findViewById(R.id.iv_tab_icon);
CustomTabEntity tabEntity = mTabEntitys.get(i);
iv_tab_icon.setImageResource(isSelect ? tabEntity.getTabSelectedIcon() : tabEntity.getTabUnselectedIcon());
Expand Down Expand Up @@ -598,6 +628,11 @@ public void setTextsize(float textsize) {
updateTabStyles();
}

public void setmTextSelectSize(int textSelectSize) {
this.mTextSelectSize = textSelectSize;
updateTabStyles();
}

public void setTextSelectColor(int textSelectColor) {
this.mTextSelectColor = textSelectColor;
updateTabStyles();
Expand Down Expand Up @@ -885,7 +920,9 @@ public void setMsgMargin(int position, float leftPadding, float bottomPadding) {
}
}

/** 当前类只提供了少许设置未读消息属性的方法,可以通过该方法获取MsgView对象从而各种设置 */
/**
* 当前类只提供了少许设置未读消息属性的方法,可以通过该方法获取MsgView对象从而各种设置
*/
public MsgView getMsgView(int position) {
if (position >= mTabCount) {
position = mTabCount - 1;
Expand Down
Loading