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

The following examples show how to use android.support.v7.widget.Toolbar#setNavigationIcon() . 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: SettingActivity.java    From ZhihuDaily with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_setting);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back);
    toolbar.setTitle("设置");
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    getFragmentManager()
            .beginTransaction()
            .add(R.id.container, new SettingFragment())
            .commit();
}
 
Example 2
Source File: AdvancedExampleActivity.java    From Theming-Android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_advanced);

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

    AttributeExtractor extractor = new AttributeExtractor();
    Drawable upDrawable = extractor.extractDrawable(this, R.attr.actionUp);
    toolbar.setNavigationIcon(upDrawable);

    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.card_list);
    recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    recyclerView.setAdapter(new SimpleCardAdapter());

    RecyclerView themesList = (RecyclerView) findViewById(R.id.themes_list);
    themesList.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
    themesList.setAdapter(new ThemePickerAdapter(extractor, onThemeSelectedListener));

    setTitle(R.string.Advanced_Example);
}
 
Example 3
Source File: Navigator.java    From Pioneer with Apache License 2.0 6 votes vote down vote up
/**
 * 设置 Toolbar 上的 导航图标与事件
 * @return 返回导航图标是否可见
 */
public static boolean setupToolbarNavigation(final Activity activity, Toolbar toolbar) {
    if (canNavigateBack(activity)) {
        toolbar.setNavigationIcon(R.drawable.ic_ab_back);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.onBackPressed();
            }
        });
        return true;
    } else {
        toolbar.setNavigationIcon(null);
        return false;
    }
}
 
Example 4
Source File: IpAddressCheckerActivity.java    From FwdPortForwardingApp with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ipaddress_checker);

    Toolbar toolbar = getActionBarToolbar();
    setSupportActionBar(toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
}
 
Example 5
Source File: SpotInfoFragment.java    From android with MIT License 5 votes vote down vote up
private void setupLayout(View view) {
    if (isExpanded) {
        final Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
        if (toolbar != null) {
            toolbar.setNavigationIcon(R.drawable.ic_navigation_arrow_back);
            TypefaceHelper.setTitle(getActivity(), toolbar, mTitle);
            toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    getActivity().onBackPressed();
                }
            });
            toolbar.inflateMenu(R.menu.menu_spot_info);
            toolbar.setOnMenuItemClickListener(this);
        }

        // Setup the recycler view
        final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        vRecyclerView.setLayoutManager(layoutManager);
    } else {
        view.setOnClickListener(this);

        vTitle.setText(mTitle);

        vCheckinBtn.setOnClickListener(this);
    }
}
 
Example 6
Source File: LockedCompatActivity.java    From LolliPin with MIT License 5 votes vote down vote up
private void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.id_toolbar);
    setSupportActionBar(toolbar);

    toolbar.setTitle("Title");
    toolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
    toolbar.setSubtitle("SubTitle");
    toolbar.setSubtitleTextColor(getResources().getColor(android.R.color.white));
    toolbar.setLogo(R.drawable.ic_launcher);
    toolbar.setNavigationIcon(R.drawable.ic_menu_white_36dp);
}
 
Example 7
Source File: MainActivity.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);

   Log.i(TAG, "%% onCreate");
   Log.i(TAG, "Olympus Version: " + APP_VERSION);

   // For TestFairy troubleshooting. IMPORTANT: remove for production apps, as TestFairy sends logs, screenshots, etc to their servers
   //TestFairy.begin(this, "#TESTFAIRY_APP_TOKEN");
   if (BuildConfig.ENABLE_TEST_FAIRY_RUNTIME) {
      TestFairy.begin(this, BuildConfig.TESTFAIRY_APP_TOKEN);
   }

   Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
   setSupportActionBar(toolbar);
   // TODO set proper image at xhdpi with 48x48
   toolbar.setNavigationIcon(R.drawable.bar_icon_24dp);
   toolbar.setTitle(getTitle());

   listFragment = (MainFragment) getSupportFragmentManager().findFragmentById(R.id.item_list);

   btnAdd = (FloatingActionButton) findViewById(R.id.imageButton_add);
   btnAdd.setOnClickListener(this);
   lblOngoingCall = findViewById(R.id.resume_call);
   lblOngoingCall.setOnClickListener(this);

   alertDialog = new AlertDialog.Builder(MainActivity.this, R.style.SimpleAlertStyle).create();

   PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
   prefs = PreferenceManager.getDefaultSharedPreferences(this);

   // No longer needed, we'll change with toast
   // set it to wifi by default to avoid the status message when starting with wifi
   //previousConnectivityStatus = RCConnectivityStatus.RCConnectivityStatusWiFi;
}
 
Example 8
Source File: BaseWebActivity.java    From FwdPortForwardingApp with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.base_web_activity);

    // Set up toolbar
    final Toolbar toolbar = getActionBarToolbar();
    setSupportActionBar(toolbar);

    toolbar.setNavigationIcon(R.drawable.ic_close_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    final WebView webView = (WebView) findViewById(R.id.help_webview);
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.setWebViewClient(new MyWebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setAppCacheEnabled(false);
    webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

    // Hardware acceleration for web view
    webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);

    webView.loadUrl(url);
}
 
Example 9
Source File: BaseActivity.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
private void setupToolbar() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(getMenuName());
    toolbar.setNavigationIcon(R.drawable.ic_drawer);
    toolbar.setLogo(R.drawable.ic_icon);
    setSupportActionBar(toolbar);
}
 
Example 10
Source File: SettingsActivity.java    From Expense-Tracker-App with MIT License 5 votes vote down vote up
private void setToolbar(Toolbar mToolbar) {
    setSupportActionBar(mToolbar);
    getDelegate().getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mToolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_black_24dp));
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
}
 
Example 11
Source File: FaceSwapperActivity.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 5 votes vote down vote up
private void setupToolbar() {
    // The action bar. Set icon and remove title.
    toolbar = (Toolbar) findViewById(R.id.main_toolbar);

    if (toolbar != null) {
        toolbar.setNavigationIcon(R.mipmap.ic_launcher);
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
    }
}
 
Example 12
Source File: SettingActivity.java    From sensordatacollector with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    // init view
    ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
    ScrollView toolbarContainer = (ScrollView) View.inflate(this, R.layout.preferences, null);
    root.removeAllViews();
    root.addView(toolbarContainer);

    // init toolbar
    Toolbar mToolBar = (Toolbar) toolbarContainer.findViewById(R.id.pref_toolbar);
    mToolBar.setTitle(getTitle());
    mToolBar.setNavigationIcon(android.R.drawable.ic_menu_revert); //TODO
    mToolBar.setNavigationOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            finish();
        }
    });

    // start transaction
    getFragmentManager().beginTransaction().replace(R.id.pref_content_frame, new Prefs1Fragment()).commit();
}
 
Example 13
Source File: LabelsActivity.java    From YuanNewsForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void initToolbar(Toolbar toolbar) {
    setTitle("关注兴趣标签");
    toolbar.setNavigationIcon(R.drawable.ic_action_arrow_left);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
}
 
Example 14
Source File: UserifoActivity.java    From YuanNewsForAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void initToolbar(Toolbar toolbar) {
    setTitle("用户信息编辑");
    toolbar.setNavigationIcon(R.drawable.ic_action_arrow_left);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
}
 
Example 15
Source File: DemoActivity.java    From material-menu with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Setup
    setContentView(R.layout.demo);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    MaterialMenuDrawable materialMenu = new MaterialMenuDrawable(this, Color.WHITE, Stroke.THIN);
    toolbar.setNavigationIcon(materialMenu);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override public void onClick(View v) {
            // random state
            actionBarMenuState = generateState(actionBarMenuState);
            getMaterialMenu(toolbar).animateIconState(intToState(actionBarMenuState));
        }
    });

    // Demo view initialization
    initViews();
    drawerLayout.postDelayed(new Runnable() {
        @Override public void run() {
            drawerLayout.openDrawer(GravityCompat.START);
        }
    }, 1500);
}
 
Example 16
Source File: BaseBackFragment.java    From fingerpoetry-android with Apache License 2.0 5 votes vote down vote up
protected void initToolbarNav(Toolbar toolbar, boolean isBack, boolean initMenu) {
    if (isBack) {
        toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    }
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            _mActivity.onBackPressed();
        }
    });
    if (initMenu) {
        initToolbarMenu(toolbar);
    }
}
 
Example 17
Source File: BaseSwipeBackFragment.java    From fingerpoetry-android with Apache License 2.0 5 votes vote down vote up
public void initToolbarNav(Toolbar toolbar) {
    toolbar.setTitle("SwipeBackActivity的Fragment");
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            _mActivity.onBackPressed();
        }
    });
}
 
Example 18
Source File: ConferenceActivity.java    From conference-app with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    if (Utils.isLollipop()) {
        setupLollipop();
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_conference);

    simpleDateFormat = new SimpleDateFormat("E, HH:mm", Locale.ENGLISH);
    simpleDateFormat2 = new SimpleDateFormat(" - HH:mm", Locale.ENGLISH);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        toolbar.setTitle(null);
        toolbar.setNavigationIcon(getResources()
                    .getDrawable(R.drawable.ic_arrow_back_white_24dp));
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    mConference = getIntent().getParcelableExtra("conference");

    fab = (FloatingActionButton)findViewById(R.id.fab);
    ((TextView)findViewById(R.id.headline)).setText(mConference.getHeadeline());
    ((TextView)findViewById(R.id.speaker)).setText(mConference.getSpeaker());
    ((TextView)findViewById(R.id.text)).setText(mConference.getText());
    ((TextView)findViewById(R.id.location)).setText(String.format(getString(R.string.location),
            mConference.getLocation()));
    ((TextView)findViewById(R.id.date)).setText(
            simpleDateFormat.format(new Date(mConference.getStartDate()))
                    + simpleDateFormat2.format(new Date(mConference.getEndDate())));

    Picasso.with(getApplicationContext())
            .load(mConference.getSpeakerImageUrl())
            .transform(((BaseApplication) getApplicationContext()).mPicassoTransformation)
            .into((ImageView) findViewById(R.id.image));
    setupFAB();
}
 
Example 19
Source File: EditRuleActivity.java    From FwdPortForwardingApp with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // If we can't locate the id, then we can't continue
    if (!getIntent().getExtras().containsKey(RuleHelper.RULE_MODEL_ID)) {

        /// Show toast containing message to the user
        Toast.makeText(this, NO_RULE_ID_FOUND_TOAST_MESSAGE,
                Toast.LENGTH_SHORT).show();

        Log.e(TAG, NO_RULE_ID_FOUND_LOG_MESSAGE);

        onBackPressed();

        // Return from the method - ensure we don't continue
        return;
    }
    ruleModelId = getIntent().getExtras().getLong(RuleHelper.RULE_MODEL_ID);

    setContentView(R.layout.edit_rule_activity);

    // Obtain the FirebaseAnalytics instance.
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    // Set up toolbar
    Toolbar toolbar = getActionBarToolbar();
    setSupportActionBar(toolbar);

    toolbar.setNavigationIcon(R.drawable.ic_close_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });


    // Use the base class to construct the common UI
    constructDetailUi();

    //TODO: move this
    this.db = new RuleDbHelper(this).getReadableDatabase();

    Cursor cursor = db.query(
            RuleContract.RuleEntry.TABLE_NAME,
            RuleDbHelper.generateAllRowsSelection(),
            RuleContract.RuleEntry.COLUMN_NAME_RULE_ID + "=?",
            new String[]{String.valueOf(ruleModelId)},
            null,
            null,
            null
    );

    cursor.moveToFirst();

    this.ruleModel = RuleHelper.cursorToRuleModel(cursor);
    Log.i(TAG, Boolean.toString(ruleModel.isEnabled()));
    // Close the DB
    cursor.close();
    db.close();

    // Set up the switchBar for enabling/disabling
    switchBar = (SwitchBar) findViewById(R.id.switch_bar);
    switchBar.show();
    switchBar.setChecked(this.ruleModel.isEnabled());
    /*
    Set the text fields content
     */
    TextInputEditText newRuleNameEditText = (TextInputEditText) findViewById(R.id.new_rule_name);
    newRuleNameEditText.setText(ruleModel.getName());

    TextInputEditText newRuleFromPortEditText = (TextInputEditText) findViewById(R.id.new_rule_from_port);
    newRuleFromPortEditText.setText(String.valueOf(ruleModel.getFromPort()));

    TextInputEditText newRuleTargetIpAddressEditText = (TextInputEditText) findViewById(R.id.new_rule_target_ip_address);
    newRuleTargetIpAddressEditText.setText(ruleModel.getTargetIpAddress());

    TextInputEditText newRuleTargetPortEditText = (TextInputEditText) findViewById(R.id.new_rule_target_port);
    newRuleTargetPortEditText.setText(String.valueOf(ruleModel.getTargetPort()));

    /*
    Set the spinners content
     */
    //from interface spinner
    Log.i(TAG, "FROM SPINNER : " + fromInterfaceSpinner.toString());
    Log.i(TAG, "FROM INTERFACE : " + this.ruleModel.getFromInterfaceName());
    fromInterfaceSpinner.setSelection(fromSpinnerAdapter.getPosition(this.ruleModel.getFromInterfaceName()));

    // Protocol spinner
    protocolSpinner.setSelection(protocolAdapter.getPosition(RuleHelper.getRuleProtocolFromModel(this.ruleModel)));


    // Set up tracking
    // Get tracker.
    tracker = ((FwdApplication) this.getApplication()).getDefaultTracker();
}
 
Example 20
Source File: ToolBarUtil.java    From Android-Architecture with Apache License 2.0 3 votes vote down vote up
/**
 * 设置Toolbar左边按钮
 *
 * @param toolbar
 * @param resId
 * @param descId
 * @param listener
 */
public static void setToolbarNavigation(Toolbar toolbar, int resId, int descId, View.OnClickListener listener) {
    if (toolbar == null) return;
    toolbar.setNavigationIcon(resId);
    toolbar.setNavigationContentDescription(descId);
    toolbar.setNavigationOnClickListener(listener);
}