forked from hackware1993/MagicIndicator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9704e64
commit 045b73c
Showing
7 changed files
with
115 additions
and
28 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...c/main/java/net/lucode/hackware/magicindicatordemo/example/DynamicTabExampleActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,94 @@ | ||
package net.lucode.hackware.magicindicatordemo.example; | ||
|
||
import android.content.Context; | ||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
import android.support.v4.view.ViewPager; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
import net.lucode.hackware.magicindicator.MagicIndicator; | ||
import net.lucode.hackware.magicindicator.ViewPagerHelper; | ||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator; | ||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter; | ||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator; | ||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView; | ||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView; | ||
import net.lucode.hackware.magicindicatordemo.R; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class DynamicTabExampleActivity extends AppCompatActivity { | ||
private static final String[] CHANNELS = new String[]{"CUPCAKE", "DONUT", "ECLAIR", "GINGERBREAD", "HONEYCOMB", "ICE_CREAM_SANDWICH", "JELLY_BEAN", "KITKAT", "LOLLIPOP", "M", "NOUGAT"}; | ||
private List<String> mDataList = new ArrayList<String>(Arrays.asList(CHANNELS)); | ||
private ExamplePagerAdapter mExamplePagerAdapter = new ExamplePagerAdapter(mDataList); | ||
|
||
private ViewPager mViewPager; | ||
private MagicIndicator mMagicIndicator; | ||
private CommonNavigator mCommonNavigator; | ||
|
||
private Toast mToast; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_dynamic_tab_example_layout); | ||
|
||
mViewPager = (ViewPager) findViewById(R.id.view_pager); | ||
mViewPager.setAdapter(mExamplePagerAdapter); | ||
|
||
mMagicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator1); | ||
mMagicIndicator.setBackgroundColor(Color.parseColor("#d43d3d")); | ||
mCommonNavigator = new CommonNavigator(this); | ||
mCommonNavigator.setSkimOver(true); | ||
mCommonNavigator.setAdapter(new CommonNavigatorAdapter() { | ||
|
||
@Override | ||
public int getCount() { | ||
return mDataList.size(); | ||
} | ||
|
||
@Override | ||
public IPagerTitleView getTitleView(Context context, final int index) { | ||
ClipPagerTitleView clipPagerTitleView = new ClipPagerTitleView(context); | ||
clipPagerTitleView.setText(mDataList.get(index)); | ||
clipPagerTitleView.setTextColor(Color.parseColor("#f2c4c4")); | ||
clipPagerTitleView.setClipColor(Color.WHITE); | ||
clipPagerTitleView.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
mViewPager.setCurrentItem(index); | ||
} | ||
}); | ||
return clipPagerTitleView; | ||
} | ||
|
||
@Override | ||
public IPagerIndicator getIndicator(Context context) { | ||
return null; | ||
} | ||
}); | ||
mMagicIndicator.setNavigator(mCommonNavigator); | ||
ViewPagerHelper.bind(mMagicIndicator, mViewPager); | ||
|
||
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT); | ||
} | ||
|
||
public void randomPage(View view) { | ||
mDataList.clear(); | ||
int total = new Random().nextInt(CHANNELS.length); | ||
for (int i = 0; i <= total; i++) { | ||
mDataList.add(CHANNELS[i]); | ||
} | ||
|
||
mCommonNavigator.notifyDataSetChanged(); // must call firstly | ||
mExamplePagerAdapter.notifyDataSetChanged(); | ||
|
||
mToast.setText("" + mDataList.size() + " page"); | ||
mToast.show(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 18 additions & 11 deletions
29
app/src/main/res/layout/activity_dynamic_tab_example_layout.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/activity_dynamic_tab_example" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
android:orientation="vertical" | ||
tools:context="net.lucode.hackware.magicindicatordemo.example.DynamicTabExampleActivity"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
<net.lucode.hackware.magicindicator.MagicIndicator | ||
android:id="@+id/magic_indicator1" | ||
android:layout_width="match_parent" | ||
android:layout_height="@dimen/common_navigator_height" /> | ||
|
||
<android.support.v4.view.ViewPager | ||
android:id="@+id/view_pager" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_weight="1" /> | ||
|
||
<Button | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_centerInParent="true" | ||
android:text="coming soon!" /> | ||
android:onClick="randomPage" | ||
android:text="@string/random_page" /> | ||
|
||
</RelativeLayout> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters