ไลบรารีนี้สร้างขึ้นจาก เวอร์ชัน 24.2.1 ใช้ได้แต่เตือน
build.gradle (Project: MyApplication)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.1.4' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() maven { url "https://jitpack.io" } } } task clean(type: Delete) { delete rootProject.buildDir } |
build.gradle (Module: app)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
apply plugin: 'com.android.application' android { compileSdkVersion 26 defaultConfig { applicationId "com.phaisarn.myapplication" minSdkVersion 21 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:support-v4:26.1.0' implementation 'com.github.gilgoldzweig:EasyTab:1.1.1' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' } |
activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <goldzweigapps.tabs.View.EasyTabs android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/EasyTabs"/> </LinearLayout> |
MainActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
package com.phaisarn.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import goldzweigapps.tabs.Builder.EasyTabsBuilder; import goldzweigapps.tabs.View.EasyTabs; import goldzweigapps.tabs.Colors.EasyTabsColors; import goldzweigapps.tabs.Items.TabItem; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); createTabs(); } private void createTabs() { EasyTabs tabs = (EasyTabs) findViewById(R.id.EasyTabs); EasyTabsBuilder.init(tabs) .addTabs( new TabItem(new Fragment1(), "Lollipop"), new TabItem(new Fragment2(), "Marshmallow"), new TabItem(new Fragment3(), "Nougat")) .setBackgroundColor(EasyTabsColors.PaleGoldenrod) .setIndicatorColor(EasyTabsColors.Red) .setTextColors(EasyTabsColors.RoyalBlue, EasyTabsColors.DarkGray) .addIcons(R.drawable.ic_1, R.drawable.ic_2, R.drawable.ic_3) .HideTitle(false) .Build(); } } |
Link