Skip to content

升级设置Tab背景色的功能。支持Drawable #67

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

Open
wants to merge 3 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
9 changes: 7 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
### 1.添加XTabLayout依赖库
#### 在app目录下的build.gradle的dependencies中添加如下引用:

compile 'com.androidkun:XTabLayout:1.1.5'
compile 'com.github.791180116:XTabLayout:1.1.6'

### 2.在布局文件中设置XTabLayout属性

Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ android {
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
/* compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0+'*/
testCompile 'junit:junit:4.12'
compile project(':xtablayoutlibrary')
testImplementation 'junit:junit:4.12'
implementation project(':xtablayoutlibrary')
}
18 changes: 16 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@

buildscript {
repositories {
maven{ url 'http://maven.oschina.net/content/groups/public/'}
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://maven.aliyun.com/repository/releases' }
maven { url 'https://maven.aliyun.com/repository/public/' }
google()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.novoda:bintray-release:0.3.4'
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.novoda:bintray-release:0.9.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
maven{ url 'http://maven.oschina.net/content/groups/public/'}
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://maven.aliyun.com/repository/releases' }
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://maven.aliyun.com/repository/spring/' }
google()
mavenCentral()
jcenter()
maven {url 'https://jitpack.io'}
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Wed Dec 30 10:52:57 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
12 changes: 6 additions & 6 deletions xtablayoutlibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
api fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0+'
testCompile 'junit:junit:4.12'
api 'com.android.support:appcompat-v7:23.4.0'
api 'com.android.support:design:23.4.0+'
testImplementation 'junit:junit:4.12'
}

publish {
userOrg = 'androidkun'
groupId = 'com.androidkun'
artifactId = 'XTabLayout'
publishVersion = '1.1.5'
publishVersion = '1.1.6'
desc = 'Added support to modify text size and indicator width based on the original TabLayout.'
website = 'https://github.com/AndroidKun/XTabLayout'
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public interface OnTabSelectedListener {
private boolean xTabTextSelectedBold;
private float mTabTextMultiLineSize;

private final int xTabBackgroundColor;
private final int xTabSelectedBackgroundColor;
private final Drawable xTabBackgroundColor;
private final Drawable xTabSelectedBackgroundColor;

private int mTabMaxWidth = Integer.MAX_VALUE;
private final int mRequestedTabMinWidth;
Expand Down Expand Up @@ -305,8 +305,8 @@ public XTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
INVALID_WIDTH);
mRequestedTabMaxWidth = a.getDimensionPixelSize(R.styleable.XTabLayout_xTabMaxWidth,
INVALID_WIDTH);
xTabBackgroundColor = a.getColor(R.styleable.XTabLayout_xTabBackgroundColor, 0);
xTabSelectedBackgroundColor = a.getColor(R.styleable.XTabLayout_xTabSelectedBackgroundColor, 0);
xTabBackgroundColor = a.getDrawable(R.styleable.XTabLayout_xTabBackgroundColor);
xTabSelectedBackgroundColor = a.getDrawable(R.styleable.XTabLayout_xTabSelectedBackgroundColor);

mContentInsetStart = a.getDimensionPixelSize(R.styleable.XTabLayout_xTabContentStart, 0);
mMode = a.getInt(R.styleable.XTabLayout_xTabMode, MODE_FIXED);
Expand Down Expand Up @@ -1488,13 +1488,14 @@ public boolean performClick() {
}
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void setSelected(boolean selected) {
final boolean changed = (isSelected() != selected);
super.setSelected(selected);
if (!selected) {
if (xTabBackgroundColor != 0) {
setBackgroundColor(xTabBackgroundColor);
if (xTabBackgroundColor != null) {
setBackground(xTabBackgroundColor);
}
mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabTextSize);
if (xTabTextBold) {
Expand All @@ -1504,8 +1505,8 @@ public void setSelected(boolean selected) {
}
}
if (changed && selected) {
if (xTabSelectedBackgroundColor != 0) {
setBackgroundColor(xTabSelectedBackgroundColor);
if (xTabSelectedBackgroundColor != null) {
setBackground(xTabSelectedBackgroundColor);
}
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);

Expand Down