use of android.support.design.widget.TabLayout in project Fragmentation by YoKeyword.
the class DiscoverFragment method initView.
private void initView(View view) {
Toolbar mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
TabLayout mTabLayout = (TabLayout) view.findViewById(R.id.tab_layout);
ViewPager mViewPager = (ViewPager) view.findViewById(R.id.viewPager);
mToolbar.setTitle("发现");
initToolbarNav(mToolbar);
mTabLayout.addTab(mTabLayout.newTab().setText(R.string.recommend));
mTabLayout.addTab(mTabLayout.newTab().setText(R.string.hot));
mTabLayout.addTab(mTabLayout.newTab().setText(R.string.favorite));
mViewPager.setAdapter(new DiscoverFragmentAdapter(getChildFragmentManager()));
mTabLayout.setupWithViewPager(mViewPager);
}
use of android.support.design.widget.TabLayout in project RxBinding by JakeWharton.
the class RxTabLayoutTest method selectionEventsNoInitial.
@Test
@UiThreadTest
public void selectionEventsNoInitial() {
TabLayout empty = new TabLayout(context);
RecordingObserver<TabLayoutSelectionEvent> o = new RecordingObserver<>();
RxTabLayout.selectionEvents(empty).subscribe(o);
o.assertNoMoreEvents();
}
use of android.support.design.widget.TabLayout in project RxBinding by JakeWharton.
the class RxTabLayoutTest method selectionsNoInitial.
@Test
@UiThreadTest
public void selectionsNoInitial() {
TabLayout empty = new TabLayout(context);
RecordingObserver<TabLayout.Tab> o = new RecordingObserver<>();
RxTabLayout.selections(empty).subscribe(o);
o.assertNoMoreEvents();
}
use of android.support.design.widget.TabLayout in project RecyclerViewPager by lsjwzh.
the class MaterialDemoWithLoopPagerActivity method initTabLayout.
private void initTabLayout() {
//给TabLayout增加Tab, 并关联ViewPager
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
TabLayoutSupport.setupWithViewPager(tabLayout, mRecyclerView, mAdapter);
}
use of android.support.design.widget.TabLayout in project Reader by TheKeeperOfPie.
the class FragmentNewMessage method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_new_message, container, false);
layoutCoordinator = (CoordinatorLayout) view.findViewById(R.id.layout_coordinator);
layoutAppBar = (AppBarLayout) view.findViewById(R.id.layout_app_bar);
scrollText = (NestedScrollView) view.findViewById(R.id.scroll_text);
textAuthor = (TextView) view.findViewById(R.id.text_author);
textAuthor.setText(getString(R.string.sending_from) + " " + controllerUser.getUser().getName());
editTextRecipient = (EditText) view.findViewById(R.id.edit_recipient);
editTextSubject = (EditText) view.findViewById(R.id.edit_subject);
editTextMessage = (EditText) view.findViewById(R.id.edit_message);
Bundle arguments = getArguments();
editTextRecipient.setText(arguments.getString(ARG_RECIPIENT));
editTextSubject.setText(arguments.getString(ARG_SUBJECT));
editTextMessage.setText(arguments.getString(ARG_MESSAGE));
toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setTitle(getString(R.string.message));
toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
toolbar.setNavigationOnClickListener(v -> {
UtilsInput.hideKeyboard(editTextMessage);
mListener.onNavigationBackClick();
});
toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
setUpOptionsMenu();
View.OnFocusChangeListener onFocusChangeListener = (v, hasFocus) -> {
if (hasFocus) {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
};
editTextRecipient.setOnFocusChangeListener(onFocusChangeListener);
editTextSubject.setOnFocusChangeListener(onFocusChangeListener);
editTextMessage.setOnFocusChangeListener(onFocusChangeListener);
editMarginDefault = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
editMarginWithActions = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 56, getResources().getDisplayMetrics());
textPreview = (TextView) view.findViewById(R.id.text_preview);
viewDivider = view.findViewById(R.id.view_divider);
toolbarActions = (Toolbar) view.findViewById(R.id.toolbar_actions);
toolbarActions.inflateMenu(R.menu.menu_editor_actions);
toolbarActions.setOnMenuItemClickListener(this);
tabLayout = (TabLayout) view.findViewById(R.id.layout_tab);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
tabLayout.setTabTextColors(themer.getColorFilterTextMuted().getColor(), themer.getColorFilterPrimary().getColor());
viewPager = (ViewPager) view.findViewById(R.id.view_pager);
viewPager.setAdapter(new PagerAdapter() {
@Override
public CharSequence getPageTitle(int position) {
switch(position) {
case PAGE_BODY:
return getString(R.string.page_message);
case PAGE_PREVIEW:
return getString(R.string.page_preview);
}
return super.getPageTitle(position);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
return viewPager.getChildAt(position);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
}
@Override
public int getCount() {
return viewPager.getChildCount();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
});
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
if (position == PAGE_BODY && toolbarActions.getVisibility() == View.VISIBLE) {
float translationY = positionOffset * (toolbarActions.getHeight() + viewDivider.getHeight());
viewDivider.setTranslationY(translationY);
toolbarActions.setTranslationY(translationY);
}
}
@Override
public void onPageSelected(int position) {
if (position == PAGE_PREVIEW) {
if (editTextMessage.length() == 0) {
textPreview.setText(R.string.empty_reply_preview);
} else {
textPreview.setText(Html.fromHtml(Processor.process(editTextMessage.getText().toString())));
}
}
itemHideActions.setVisible(position == PAGE_BODY);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
tabLayout.setupWithViewPager(viewPager);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
layoutCaptcha = (RelativeLayout) view.findViewById(R.id.layout_captcha);
imageCaptcha = (ImageView) view.findViewById(R.id.image_captcha);
editCaptcha = (EditText) view.findViewById(R.id.edit_captcha);
buttonCaptchaRefresh = (ImageButton) view.findViewById(R.id.button_captcha_refresh);
buttonCaptchaRefresh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadCaptcha();
}
});
reddit.needsCaptcha().subscribe(new Observer<String>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onNext(String response) {
Log.d(TAG, "needsCaptcha onNext: " + response);
if ("true".equalsIgnoreCase(response)) {
layoutCaptcha.setVisibility(View.VISIBLE);
loadCaptcha();
}
}
});
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Menu menu = toolbarActions.getMenu();
int maxNum = (int) (view.getWidth() / TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, getResources().getDisplayMetrics()));
int numShown = 0;
for (int index = 0; index < menu.size(); index++) {
MenuItem menuItem = menu.getItem(index);
menuItem.getIcon().setColorFilter(themer.getColorFilterIcon());
if (numShown++ < maxNum - 1) {
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
} else {
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}
}
// Toggle visibility to fix weird bug causing tabs to not be added
tabLayout.setVisibility(View.GONE);
tabLayout.setVisibility(View.VISIBLE);
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
return view;
}
Aggregations