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

Added setTypeface method #18

Open
wants to merge 2 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
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
Expand All @@ -24,9 +24,9 @@ android {
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile project(':libk-switchbutton')
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation project(':libk-switchbutton')
// compile 'lib.kingja.switchbutton:switchbutton:1.1.6'
compile "com.android.support:appcompat-v7:$rootProject.ext.supportVersion"
implementation "com.android.support:appcompat-v7:$rootProject.ext.supportVersion"
}
5 changes: 3 additions & 2 deletions app/src/main/java/com/kingja/switchbutton/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.kingja.switchbutton;

import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
Expand All @@ -43,8 +44,8 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

((SwitchMultiButton) findViewById(R.id.switchmultibutton1)).setText(tabTexts1).setOnSwitchListener(onSwitchListener);
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/tielanti.ttf");
((SwitchMultiButton) findViewById(R.id.switchmultibutton1)).setText(tabTexts1).setOnSwitchListener(onSwitchListener).setTypeface(typeface);
((SwitchMultiButton) findViewById(R.id.switchmultibutton2)).setText("点个Star", "狠心拒绝").setOnSwitchListener(onSwitchListener);
((SwitchMultiButton) findViewById(switchmultibutton3)).setOnSwitchListener(onSwitchListener).setSelectedTab(1);
((SwitchMultiButton) findViewById(R.id.switchmultibutton4)).setText(tabTexts4).setOnSwitchListener(onSwitchListener);
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ apply from:'config.gradle'
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.1.3'
}
}

allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
8 changes: 4 additions & 4 deletions config.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
ext {
compileSdkVersion = 25
buildToolsVersion = "25.0.3"
compileSdkVersion = 27
buildToolsVersion = "27.0.3"
minSdkVersion = 14
targetSdkVersion = 25
targetSdkVersion = 27
versionCode = 5
versionName = "1.1.5"

supportVersion = '25.3.1'
supportVersion = '27.1.1'
}
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 @@
#Sun Jul 09 18:58:12 CST 2017
#Mon Jul 30 19:31:53 IRDT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6 changes: 3 additions & 3 deletions libk-switchbutton/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile "com.android.support:appcompat-v7:$rootProject.ext.supportVersion"
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation "com.android.support:appcompat-v7:$rootProject.ext.supportVersion"
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,18 @@ public SwitchMultiButton setText(String... tagTexts) {
throw new IllegalArgumentException("the size of tagTexts should greater then 1");
}
}

/**
* set Typeface for buttons from java code
*
* @param typeface
*/
public void setTypeface(Typeface typeface) {
this.typeface = typeface;
mSelectedTextPaint.setTypeface(typeface);
mUnselectedTextPaint.setTypeface(typeface);
invalidate();
}
/*======================================save and restore======================================*/

@Override
Expand Down