我正在尝试允许我的应用支持多个主题,目前正在开发一个界面,在用户选择之前会显示所有这些主题。
如果是这样,我该怎么做呢?我想它会涉及标签活动,但除此之外我不知道。谷歌搜索并没有太多帮助:/
答案 0 :(得分:0)
好吧,我不能用花哨的鞠躬看起来帮助你。为此,你需要使用表面视图进行自定义渲染..这就说如果你可以平坦..(有些库可能会让你更近一步)你可以做一个简单的HORIZONTAL Recyclerview ..我的实现使用自定义查看寻呼机之间的交换。但是,您可以忽略该部分,标记为2
第1节tabber UI
<android.support.v7.widget.RecyclerView
android:id="@+id/custom_tab_bar"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:orientation="horizontal"
android:paddingTop="20dp"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
tools:listitem="@layout/tab_layout"
/>
我无法在4个月的时间内将tab_layout的UI显示为愚蠢的自定义。但问题是它是垂直的
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/root"
android:paddingBottom="10dp"
android:background="@color/black"
android:paddingLeft="6dp"
android:paddingRight="6dp"
> ...
代码实施
@Override
public void TabItemSelected(int position) {
mCustomTabAdapter.setSelectedPosition(position);
mCustomTabAdapter.notifyDataSetChanged();
mCustomTabBarRecyclerView.smoothScrollToPosition(position);
mViewPager.setCurrentItem(position, true);
mPageAdapter.notifyDataSetChanged();
mCustomTabBarRecyclerView.smoothScrollToPosition(position);
}
在我的ui创作中
mCustomTabBarRecyclerView.setAdapter(mCustomTabAdapter);
mCustomTabBarRecyclerView.setHasFixedSize(true);
mCustomTabBarRecyclerView.setLayoutManager(mLayoutManager);
第2节视图寻呼机。 I think I based it off this vogella example
<xx.xx.CustomViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/xx_viewpager"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
/>
CUSTOM PAGER
public class CustomViewPager extends ViewPager {
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return false;
}
}
SETUP
mViewPager.addOnPageChangeListener(getPageChangeListener());
mPageAdapter = new ProfileAdapter(getFragmentManager(),
mMemberArrayList);
mViewPager.setAdapter(mPageAdapter);
private ViewPager.OnPageChangeListener getPageChangeListener() {
return new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset,
int positionOffsetPixels) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
@Override
public void onPageSelected(final int position) {
mCustomTabAdapter.setSelectedPosition(position);
mCustomTabAdapter.notifyDataSetChanged();
mCustomTabBarRecyclerView.smoothScrollToPosition(position);
}
};
}
CUSTOM ADAPTER
public class UserProfileAdapter extends FragmentPagerAdapter {
private ArrayList<Member> mMemberArrayList = null;
private final DashboardFragment[] mFragments;
/**
* Build the set of fragments that we need for the view pages.
*/
public UserProfileAdapter(FragmentManager fm, ArrayList<Member> arrayList) {
super(fm);
mMemberArrayList = arrayList;
mFragments = new DashboardFragment[arrayList.size()];
DashboardFragment.setDataSource(arrayList);
for (int i = 0; i < arrayList.size(); i++) {
mFragments[i] = DashboardFragment.newInstance(i);
}
}
@Override
public int getCount() {
if (mMemberArrayList == null) {
return 0;
}
return mMemberArrayList.size();
}
@Override
public CharSequence getPageTitle(int position) {
return "Pos: " + position;
}
@Override
public Fragment getItem(int position) {
return mFragments[position];
}
}