-
Notifications
You must be signed in to change notification settings - Fork 194
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
ccw
committed
Dec 13, 2018
1 parent
bc65ace
commit fbe5a5c
Showing
19 changed files
with
648 additions
and
181 deletions.
There are no files selected for viewing
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
16 changes: 16 additions & 0 deletions
16
demo/src/main/java/com/chaychan/bottombarlayout/DemoBean.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.chaychan.bottombarlayout; | ||
|
||
public class DemoBean { | ||
public String name; | ||
public Class<?> clazz; | ||
|
||
public DemoBean(String name, Class<?> clazz) { | ||
this.name = name; | ||
this.clazz = clazz; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
} |
153 changes: 153 additions & 0 deletions
153
demo/src/main/java/com/chaychan/bottombarlayout/DynamicAddItemActivity.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 |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package com.chaychan.bottombarlayout; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.v4.app.FragmentTransaction; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.widget.FrameLayout; | ||
|
||
import com.chaychan.library.BottomBarItem; | ||
import com.chaychan.library.BottomBarLayout; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
/** | ||
* @author ChayChan | ||
* @description: 动态添加条目 | ||
* @date 2018/12/13 14:45 | ||
*/ | ||
public class DynamicAddItemActivity extends AppCompatActivity { | ||
|
||
private List<TabFragment> mFragmentList = new ArrayList<>(); | ||
private FrameLayout mFlContent; | ||
private BottomBarLayout mBottomBarLayout; | ||
|
||
private int[] mNormalIconIds = new int[]{ | ||
R.mipmap.tab_home_normal, R.mipmap.tab_video_normal, | ||
R.mipmap.tab_micro_normal, R.mipmap.tab_me_normal | ||
}; | ||
|
||
private int[] mSelectedIconIds = new int[]{ | ||
R.mipmap.tab_home_selected, R.mipmap.tab_video_selected, | ||
R.mipmap.tab_micro_selected, R.mipmap.tab_me_selected | ||
}; | ||
|
||
private int[] mTitleIds = new int[]{ | ||
R.string.tab_home, | ||
R.string.tab_video, | ||
R.string.tab_micro, | ||
R.string.tab_me | ||
}; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_dynamic_add_item); | ||
|
||
initView(); | ||
initData(); | ||
initListener(); | ||
} | ||
|
||
private void initView() { | ||
mFlContent = (FrameLayout) findViewById(R.id.fl_content); | ||
mBottomBarLayout = (BottomBarLayout) findViewById(R.id.bbl); | ||
} | ||
|
||
private void initData() { | ||
for (int i = 0; i < mTitleIds.length; i++) { | ||
//创建item | ||
BottomBarItem item = createBottomBarItem(i); | ||
mBottomBarLayout.addItem(item); | ||
|
||
TabFragment homeFragment = createFragment(mTitleIds[i]); | ||
mFragmentList.add(homeFragment); | ||
} | ||
|
||
changeFragment(0); //默认显示第一页 | ||
} | ||
|
||
@NonNull | ||
private TabFragment createFragment(int titleId) { | ||
TabFragment homeFragment = new TabFragment(); | ||
Bundle bundle = new Bundle(); | ||
bundle.putString(TabFragment.CONTENT, getString(titleId)); | ||
homeFragment.setArguments(bundle); | ||
return homeFragment; | ||
} | ||
|
||
private BottomBarItem createBottomBarItem(int i) { | ||
BottomBarItem item = new BottomBarItem.Builder(this) | ||
.titleTextSize(8) | ||
.titleNormalColor(R.color.tab_normal_color) | ||
.titleSelectedColor(R.color.tab_selected_color) | ||
// .openTouchBg(false) | ||
// .marginTop(5) | ||
// .itemPadding(5) | ||
// .unreadNumThreshold(99) | ||
// .unreadTextColor(R.color.white) | ||
|
||
//还有很多属性,详情请查看Builder里面的方法 | ||
//There are still many properties, please see the methods in the Builder for details. | ||
.create(mNormalIconIds[i], mSelectedIconIds[i], getString(mTitleIds[i])); | ||
return item; | ||
} | ||
|
||
private void initListener() { | ||
mBottomBarLayout.setOnItemSelectedListener(new BottomBarLayout.OnItemSelectedListener() { | ||
@Override | ||
public void onItemSelected(final BottomBarItem bottomBarItem, int previousPosition, final int currentPosition) { | ||
Log.i("MainActivity", "position: " + currentPosition); | ||
|
||
changeFragment(currentPosition); | ||
} | ||
}); | ||
} | ||
|
||
private void changeFragment(int currentPosition) { | ||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); | ||
transaction.replace(R.id.fl_content, mFragmentList.get(currentPosition)); | ||
transaction.commit(); | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
getMenuInflater().inflate(R.menu.menu, menu); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
int id = item.getItemId(); | ||
switch (id){ | ||
case R.id.action_add_item: | ||
int random = new Random().nextInt(3); | ||
//addFragment | ||
mFragmentList.add(createFragment(mTitleIds[random])); | ||
//addItem | ||
BottomBarItem bottomBarItem = createBottomBarItem(random); | ||
mBottomBarLayout.addItem(bottomBarItem); | ||
|
||
mBottomBarLayout.setCurrentItem(mFragmentList.size() - 1); | ||
break; | ||
case R.id.action_remove_item: | ||
//移除条目 | ||
mBottomBarLayout.removeItem(0); | ||
|
||
if (mFragmentList.size() != 0){ | ||
mFragmentList.remove(0); | ||
|
||
if (mFragmentList.size() != 0){ | ||
mBottomBarLayout.setCurrentItem(0); | ||
} | ||
} | ||
break; | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
} |
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
27 changes: 19 additions & 8 deletions
27
demo/src/main/java/com/chaychan/bottombarlayout/MainActivity.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,23 +1,34 @@ | ||
package com.chaychan.bottombarlayout; | ||
|
||
import android.app.ListActivity; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.ListView; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
public class MainActivity extends ListActivity { | ||
|
||
private DemoBean[] mDatas= { | ||
new DemoBean("UseWithViewPager",ViewPagerActivity.class), | ||
new DemoBean("UseWithoutViewPager",FragmentManagerActivity.class), | ||
new DemoBean("DynamicAddItem",DynamicAddItemActivity.class), | ||
|
||
}; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
} | ||
|
||
public void useVp(View view){ | ||
startActivity(new Intent(this,ViewPagerActivity.class)); | ||
ArrayAdapter<DemoBean> adapter = new ArrayAdapter<DemoBean>(this, android.R.layout.simple_list_item_1, mDatas); | ||
setListAdapter(adapter); | ||
} | ||
|
||
public void noUseVp(View view){ | ||
startActivity(new Intent(this,FragmentManagerActivity.class)); | ||
@Override | ||
protected void onListItemClick(ListView l, View v, int position, long id) { | ||
//为条目设置点击事件 | ||
DemoBean dataBean = mDatas[position]; | ||
startActivity(new Intent(this,dataBean.clazz));//跳转到对应的activity | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<FrameLayout | ||
android:id="@+id/fl_content" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_weight="1" | ||
/> | ||
|
||
<com.chaychan.library.BottomBarLayout | ||
android:id="@+id/bbl" | ||
android:layout_width="match_parent" | ||
android:layout_height="45dp" | ||
android:orientation="horizontal" | ||
android:gravity="center" | ||
android:layout_gravity="center" | ||
android:background="@color/tab_gb" | ||
/> | ||
|
||
</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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.