Java Code Examples for android.support.v7.widget.Toolbar#setOnClickListener()

The following examples show how to use android.support.v7.widget.Toolbar#setOnClickListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From Moment with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    errorContainer = (LinearLayout) findViewById(R.id.error_container);
    ImageButton errorIcon = (ImageButton) findViewById(R.id.error_icon);
    errorIcon.setOnClickListener(this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    applyFontsToTitle(toolbar);

    list = (RecyclerView) findViewById(R.id.list);
    refresh = (SwipeRefreshLayout) findViewById(R.id.refreshLayout);

    toolbar.setOnClickListener(v -> list.scrollToPosition(0));

    url = getString(R.string.pic_category_url, 21, page);
    setupRecyclerView();

    toolbar.setOnClickListener(v -> list.scrollToPosition(0));

    loadData(true);
}
 
Example 2
Source File: MainActivity.java    From IdeaTrackerPlus with MIT License 6 votes vote down vote up
private void setUpUI() {

        //Default colors
        defaultPrimaryColor = ContextCompat.getColor(this, R.color.md_blue_grey_800);
        defaultSecondaryColor = ContextCompat.getColor(this, R.color.md_teal_a400);
        defaultTextColor = ContextCompat.getColor(this, R.color.md_white);

        // Toolbar
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);
        mToolbar.setOnClickListener(this);

        // Wire the floating button
        mFab = (FloatingActionButton) findViewById(R.id.fab);
        mFab.setOnClickListener(this);
        mFab.setOnLongClickListener(this);
    }
 
Example 3
Source File: BaseAppcompatActivity.java    From ZhihuDaily with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initTheme();
    setContentView(getContentViewLayoutId());
    mToolbar = (Toolbar) findViewById(R.id.actionbarToolbar);
    mToolbar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            smoothToTop();
        }
    });

    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
        int statusBarHeight = UIUtils.getStatusBarHeight(this);
        mToolbar.setPadding(0, statusBarHeight, 0, 0);
    }
    setupActionBar();
}
 
Example 4
Source File: ToolbarActivity.java    From SeeWeather with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mAppBar = (AppBarLayout) findViewById(R.id.appbar_layout);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    if (mToolbar == null || mAppBar == null) {
        throw new IllegalStateException(
            "The subclass of ToolbarActivity must contain a toolbar.");
    }
    mToolbar.setOnClickListener(v -> onToolbarClick());
    setSupportActionBar(mToolbar);
    if (canBack()) {
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true);
    }
    if (Build.VERSION.SDK_INT >= 21) {
        mAppBar.setElevation(10.6f);
    }
}
 
Example 5
Source File: WendaContentFragment.java    From Toutiao with Apache License 2.0 6 votes vote down vote up
@Override
protected void initView(View view) {
    super.initView(view);
    Toolbar toolbar = view.findViewById(R.id.toolbar);
    initToolBar(toolbar, true, getString(R.string.title_wenda));
    toolbar.setOnClickListener(view1 -> recyclerView.smoothScrollToPosition(0));
    toolbar.setBackgroundColor(SettingUtil.getInstance().getColor());

    adapter = new MultiTypeAdapter(oldItems);
    Register.registerWendaContentItem(adapter);
    recyclerView.setAdapter(adapter);
    recyclerView.addOnScrollListener(new OnLoadMoreListener() {
        @Override
        public void onLoadMore() {
            if (canLoadMore) {
                canLoadMore = false;
                presenter.doLoadMoreData();
            }
        }
    });
    setHasOptionsMenu(true);
}
 
Example 6
Source File: NewsCommentFragment.java    From Toutiao with Apache License 2.0 6 votes vote down vote up
@Override
protected void initView(View view) {
    super.initView(view);
    Toolbar toolbar = view.findViewById(R.id.toolbar);
    initToolBar(toolbar, true, getString(R.string.title_comment));
    toolbar.setOnClickListener(view1 -> recyclerView.smoothScrollToPosition(0));
    toolbar.setBackgroundColor(SettingUtil.getInstance().getColor());

    adapter = new MultiTypeAdapter(oldItems);
    Register.registerNewsCommentItem(adapter);
    recyclerView.setAdapter(adapter);
    recyclerView.addOnScrollListener(new OnLoadMoreListener() {
        @Override
        public void onLoadMore() {
            if (canLoadMore) {
                canLoadMore = false;
                presenter.doLoadMoreData();
            }
        }
    });
    setHasOptionsMenu(true);
}
 
Example 7
Source File: NotifyActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.hotweibo_activity_layout);
    Toolbar mToolbar = (Toolbar) findViewById(R.id.hotWeiboToolbar);

    buildContent();
    mToolbar.setTitle(R.string.mentions_me);
    disPlayHomeAsUp(mToolbar);

    mToolbar.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            NotifyViewPagerFragment atme = (NotifyViewPagerFragment) getSupportFragmentManager().findFragmentByTag(NotifyViewPagerFragment.class.getName());
            atme.scrollToTop();
        }
    });
}
 
Example 8
Source File: NotifyActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.hotweibo_activity_layout);
    Toolbar mToolbar = (Toolbar) findViewById(R.id.hotWeiboToolbar);

    buildContent();
    mToolbar.setTitle(R.string.mentions_me);
    disPlayHomeAsUp(mToolbar);

    mToolbar.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            NotifyViewPagerFragment atme = (NotifyViewPagerFragment) getSupportFragmentManager().findFragmentByTag(NotifyViewPagerFragment.class.getName());
            atme.scrollToTop();
        }
    });
}
 
Example 9
Source File: MainActivity.java    From diycode with Apache License 2.0 5 votes vote down vote up
private void initMenu(ViewHolder holder) {
    Toolbar toolbar = holder.get(R.id.toolbar);
    toolbar.setLogo(R.mipmap.logo_actionbar);
    toolbar.setTitle("");
    DrawerLayout drawer = holder.get(R.id.drawer_layout);
    setSupportActionBar(toolbar);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    // 双击 666
    final GestureDetector detector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            quickToTop();   // 快速返回头部
            return super.onDoubleTap(e);
        }
    });

    toolbar.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            detector.onTouchEvent(event);
            return false;
        }
    });

    toolbar.setOnClickListener(this);

    holder.setOnClickListener(this, R.id.fab);

    loadMenuData();
}
 
Example 10
Source File: GuessingCardActivity.java    From px-android with MIT License 5 votes vote down vote up
private void loadToolbarArrow(final Toolbar toolbar) {
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
    }
    if (toolbar != null) {
        toolbar.setOnClickListener(this);
    }
}
 
Example 11
Source File: ChatActivity.java    From Game-of-Thrones with Apache License 2.0 5 votes vote down vote up
private void initToolbar() {
  toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);

  toolbar.setOnClickListener(view -> moveToDetailActivity(conversation));
  if (getSupportActionBar() != null) {
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  }
}
 
Example 12
Source File: PhotoContentFragment.java    From Toutiao with Apache License 2.0 5 votes vote down vote up
@Override
protected void initView(View view) {
    Toolbar toolbar = view.findViewById(R.id.toolbar);
    initToolBar(toolbar, true, "");
    toolbar.setOnClickListener(v -> scrollView.smoothScrollTo(0, 0));

    tv_hint = view.findViewById(R.id.tv_hint);
    tv_save = view.findViewById(R.id.tv_save);
    tv_save.setOnClickListener(this);

    viewPager = view.findViewById(R.id.viewPager);
    photoView = view.findViewById(R.id.photoView);
    webView = view.findViewById(R.id.webview);
    scrollView = view.findViewById(R.id.scrollView);

    progressBar = view.findViewById(R.id.pb_progress);
    int color = SettingUtil.getInstance().getColor();
    progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
    progressBar.show();

    swipeRefreshLayout = view.findViewById(R.id.refresh_layout);
    swipeRefreshLayout.setColorSchemeColors(SettingUtil.getInstance().getColor());
    swipeRefreshLayout.setOnRefreshListener(() -> {
        swipeRefreshLayout.post(() -> swipeRefreshLayout.setRefreshing(true));
        presenter.doLoadData(shareUrl);
    });

    setHasOptionsMenu(true);
}
 
Example 13
Source File: WendaDetailFragment.java    From Toutiao with Apache License 2.0 4 votes vote down vote up
@Override
protected void initView(View view) {
    Toolbar toolbar = view.findViewById(R.id.toolbar);
    initToolBar(toolbar, true, getString(R.string.title_wenda_detail));
    toolbar.setOnClickListener(view12 -> scrollView.smoothScrollTo(0, 0));

    webView = view.findViewById(R.id.webview);
    initWebClient();

    header_layout = view.findViewById(R.id.header_layout);
    header_layout.setBackgroundColor(SettingUtil.getInstance().getColor());

    tv_title = view.findViewById(R.id.tv_title);
    iv_user_avatar = view.findViewById(R.id.iv_user_avatar);
    tv_user_name = view.findViewById(R.id.tv_user_name);

    scrollView = view.findViewById(R.id.scrollView);
    scrollView.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, scrollX, scrollY, oldScrollX, oldScrollY) -> onHideLoading());
    scrollView.getViewTreeObserver().addOnScrollChangedListener(() -> {
        View view1 = scrollView.getChildAt(scrollView.getChildCount() - 1);
        int diff = (view1.getBottom() - (scrollView.getHeight() + scrollView.getScrollY()));
        if (diff == 0) {
            canLoadMore = false;
            presenter.doLoadMoreComment();
        }
    });

    swipeRefreshLayout = view.findViewById(R.id.refresh_layout);
    swipeRefreshLayout.setColorSchemeColors(SettingUtil.getInstance().getColor());
    swipeRefreshLayout.setOnRefreshListener(() -> {
        swipeRefreshLayout.post(() -> swipeRefreshLayout.setRefreshing(true));
        presenter.doLoadData(url);
    });

    progressBar = view.findViewById(R.id.pb_progress);
    int color = SettingUtil.getInstance().getColor();
    progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
    progressBar.show();

    recyclerView = view.findViewById(R.id.recycler_view);
    recyclerView.setHasFixedSize(true);
    // 禁止嵌套滚动
    recyclerView.setNestedScrollingEnabled(false);
    adapter = new MultiTypeAdapter(oldItems);
    Register.registerNewsCommentItem(adapter);
    recyclerView.setAdapter(adapter);

    setHasOptionsMenu(true);
}
 
Example 14
Source File: MainActivity.java    From CardStackView with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);

    mCardStackView = (CardStackView) findViewById(R.id.card_stack_view);
    mCardStackView.setOnCardClickListener(new CardStackView.OnCardClickListener() {
        @Override
        public void onClick(View view, int realIndex, int initialIndex) {
            toggleAnimation(view, initialIndex);
        }
    });
    mCardStackView.setOnPositionChangedListener(new CardStackView.OnPositionChangedListener() {
        @Override
        public void onPositionChanged(List<Integer> position) {
            StringBuilder sb = new StringBuilder();
            for (Integer integer : position) {
                sb.append(integer).append(" ");
            }
            mPreferences.edit().putString("order", sb.toString()).apply();
        }
    });

    mPreferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
    String order = mPreferences.getString("order", "");
    int[] orders;
    if (TextUtils.isEmpty(order)) {
        orders = new int[] { 0, 1, 2, 3 };
    } else {
        String[] ordersArr = order.trim().split(" ");
        orders = new int[ordersArr.length];
        for (int i = 0; i < ordersArr.length; i++) {
            orders[i] = Integer.valueOf(ordersArr[i]);
        }
    }
    mCards = initCards(orders);
    mCardAdapter = new SimpleCardAdapter(this, mCards);

    mCardStackView.setAdapter(mCardAdapter);

    mToolbar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            System.out.println(mPreferences.getString("order", ""));
        }
    });
}
 
Example 15
Source File: SwipeableCard.java    From SwipeableCard with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize Toolbar.
 * @param context Context
 */
@SuppressWarnings("deprecation")
private void initToolbar(Context context, OptionView option)
{
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(titleAttr);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if(colorTitleAttr == 0)
        {
            toolbar.setTitleTextColor(ContextCompat.getColor(context, option.getColorTitle()));
        }
        else {
            toolbar.setTitleTextColor(colorTitleAttr);
        }
        if(colorToolbarAttr == 0)
        {
            toolbar.setBackgroundColor((ContextCompat.getColor(context, option.getColorToolbar())));
        }else {

            toolbar.setBackgroundColor(colorToolbarAttr);
        }

    } else {
        if(colorTitleAttr == 0)
        {
            toolbar.setTitleTextColor(getResources().getColor(option.getColorTitle()));
        }
        else {
            toolbar.setTitleTextColor(colorTitleAttr);
        }
        if(colorToolbarAttr == 0) {
            toolbar.setBackgroundColor(getResources().getColor(option.getColorToolbar()));
        }else{
            toolbar.setBackgroundColor(colorToolbarAttr);
        }
    }
    if (option.isMenuItem()) {
        //Reset menù item (avoids duplicate)
        toolbar.getMenu().clear();
        //Set new menù item
        toolbar.inflateMenu(option.getMenuItem());
        toolbar.setOnMenuItemClickListener(option.getToolbarListener());
    }
    if(option.isAutoAnimation()) {
        toolbar.setOnClickListener(this);
    }else{
        toolbar.setOnClickListener(null);
    }
}