Java Code Examples for android.support.v7.app.ActionBar.setHomeAsUpIndicator()

The following are Jave code examples for showing how to use setHomeAsUpIndicator() of the android.support.v7.app.ActionBar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ClouldReader   File: SlideScrollViewActivity.java   View Source Code Vote up 7 votes
private void setTitleBar() {
        setSupportActionBar(binding.titleToolBar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            //去除默认Title显示
            actionBar.setDisplayShowTitleEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(R.drawable.icon_back);
//            actionBar.setTitle(subjectsBean.getTitle());
//            actionBar.setSubtitle("主演:" + StringFormatUtil.formatName(subjectsBean.getCasts()));
        }

        // title
        binding.tvTitle.setText(subjectsBean.getTitle());
        // 副标题
        binding.tvSubtitle.setText("主演:" + StringFormatUtil.formatName(subjectsBean.getCasts()));

        binding.titleToolBar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }
 
Example 2
Project: rest-android   File: EditRequestActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_request_edit);

    ButterKnife.bind(this);

    setSupportActionBar(toolbar);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
        actionBar.setTitle(R.string.title_edit_request);
    }
}
 
Example 3
Project: changApp   File: PostulacionesActivasActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_postulaciones_activas);
    // Setting ViewPager for each Tabs
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager_pa);
    setupViewPager(viewPager);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerpa);
    // Adding menu icon to Toolbar
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        VectorDrawableCompat indicator
                = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu, getTheme());
        indicator.setTint(ResourcesCompat.getColor(getResources(),R.color.white,getTheme()));
        supportActionBar.setHomeAsUpIndicator(indicator);
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }

}
 
Example 4
Project: mesh-core-on-android   File: MainActivity.java   View Source Code Vote up 5 votes
private void initNavigation() {
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navView = (NavigationView) findViewById(R.id.nav_view);
      ActionBar actionBar = getSupportActionBar();
      if (actionBar != null) {
          actionBar.setDisplayHomeAsUpEnabled(true);
          actionBar.setHomeAsUpIndicator(R.drawable.ic_menu);
      }
navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(MenuItem item) {
              switch (item.getItemId()) {
                  case R.id.nav_devices:
                      break;
                  case R.id.nav_lab:
                      break;
                  case R.id.nav_information:
                      break;
                  case R.id.nav_settings:
                      break;
                  case R.id.nav_about:
                      break;
              }
              mDrawerLayout.closeDrawers();
              return true;
          }
      });

      mSwipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh);
      mSwipeRefresh.setColorSchemeResources(R.color.colorPrimary);
      mSwipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
              if (mMeshSvc != null && !mMeshSvc.isOnline()) {
                  refreshDeviceNode();
              }
          }
      });
  }
 
Example 5
Project: MeetMusic   File: HomeActivity.java   View Source Code Vote up 5 votes
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        dbManager = DBManager.getInstance(HomeActivity.this);
        toolbar = (Toolbar)findViewById(R.id.home_activity_toolbar);
        setSupportActionBar(toolbar);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        navView = (NavigationView) findViewById(R.id.nav_view);
        View headerView = navView.getHeaderView(0);
        navHeadIv = (ImageView)headerView.findViewById(R.id.nav_head_bg_iv);
        loadBingPic();
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(R.drawable.drawer_menu);
        }
        refreshNightModeTitle();
        navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem item) {
                mDrawerLayout.closeDrawers();
                switch (item.getItemId()){
                    case R.id.nav_theme:
                        isStartTheme = true;
                        Intent intentTheme = new Intent(HomeActivity.this,ThemeActivity.class);
                        startActivity(intentTheme);
                        break;
                    case R.id.nav_night_mode:
                        int preTheme = 0;
                        if(MyMusicUtil.getNightMode(HomeActivity.this)){
                            //当前为夜间模式,则恢复之前的主题
                            MyMusicUtil.setNightMode(HomeActivity.this,false);
                            preTheme = MyMusicUtil.getPreTheme(HomeActivity.this);
                            MyMusicUtil.setTheme(HomeActivity.this,preTheme);
                        }else {
                            //当前为白天模式,则切换到夜间模式
                            MyMusicUtil.setNightMode(HomeActivity.this,true);
                            MyMusicUtil.setTheme(HomeActivity.this,ThemeActivity.THEME_SIZE-1);
                        }
//                        Intent intentNight = new Intent(HomeActivity.this,HomeActivity.class);
//                        startActivity(intentNight);
                        recreate();
                        refreshNightModeTitle();
//                        overridePendingTransition(R.anim.start_anim,R.anim.out_anim);
                        break;
                    case R.id.nav_about_me:
                        Intent aboutTheme = new Intent(HomeActivity.this,AboutActivity.class);
                        startActivity(aboutTheme);
                        break;
                    case R.id.nav_logout:
                        finish();
                        Intent intentBroadcast = new Intent(MusicPlayerService.PLAYER_MANAGER_ACTION);
                        intentBroadcast.putExtra(Constant.COMMAND, Constant.COMMAND_RELEASE);
                        sendBroadcast(intentBroadcast);
                        Intent stopIntent = new Intent(HomeActivity.this,MusicPlayerService.class);
                        stopService(stopIntent);
                        break;
                }
                return true;
            }
        });
        init();

        Intent startIntent = new Intent(HomeActivity.this,MusicPlayerService.class);
        startService(startIntent);

    }
 
Example 6
Project: GankReader   File: WebViewActivity.java   View Source Code Vote up 5 votes
private void initTitle() {
    //设置状态栏颜色
    StatusBarUtil.setColor(this, CommonUtils.getColor(R.color.colorTheme), 0);
    //初始化相关控件
    mProgressBar = (ProgressBar) findViewById(R.id.pb_progress);
    webView = (WebView) findViewById(R.id.webview_detail);
    videoFullView = (FrameLayout) findViewById(R.id.video_fullView);
    mTitleToolBar = (Toolbar) findViewById(R.id.title_tool_bar);

    setSupportActionBar(mTitleToolBar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        //去除默认Title显示
        actionBar.setDisplayShowTitleEnabled(false);
        //显示默认back键
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.drawable.icon_back);
    }
    setTitle(mTitle);

    //给默认back键设置点击事件
    mTitleToolBar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
}
 
Example 7
Project: starwarsshop   File: BaseActivity.java   View Source Code Vote up 5 votes
public void initMainToolbar() {
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    final ActionBar actionBar = getSupportActionBar();

    if (actionBar != null) {
        actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_black_24dp);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}
 
Example 8
Project: Customerly-Android-SDK   File: IAct_FullScreenImage.java   View Source Code Vote up 5 votes
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(this.getIntent() != null) {
        this._SourceUrl = this.getIntent().getStringExtra(EXTRA_IMAGE_SOURCE);
        if(this._SourceUrl != null) {
            ImageView _ImageView = new TouchImageView(this);
            _ImageView.setBackgroundColor(Color.WHITE);
            _ImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            _ImageView.setAdjustViewBounds(true);
            try {
                Customerly.get()._RemoteImageHandler.request(new IU_RemoteImageHandler.Request()
                        .fitCenter()
                        .load(this._SourceUrl)
                        .into(this, _ImageView)
                        .placeholder(R.drawable.io_customerly__pic_placeholder_fullscreen));
                super.setContentView(_ImageView);

                final ActionBar actionBar = this.getSupportActionBar();
                if (actionBar != null) {
                    String title;
                    if(Customerly.get().__PING__LAST_widget_color != 0) {
                        actionBar.setBackgroundDrawable(new ColorDrawable(Customerly.get().__PING__LAST_widget_color));
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                            this.getWindow().setStatusBarColor(IU_Utils.alterColor(Customerly.get().__PING__LAST_widget_color, 0.8f));
                        }

                        if (IU_Utils.getContrastColor(Customerly.get().__PING__LAST_widget_color) == Color.BLACK) {
                            actionBar.setHomeAsUpIndicator(R.drawable.io_customerly__ic_arrow_back_black_24dp);
                            title = String.format("<font color='#000000'>%1$s</font>", actionBar.getTitle());

                        } else {
                            actionBar.setHomeAsUpIndicator(R.drawable.io_customerly__ic_arrow_back_white_24dp);
                            title = String.format("<font color='#ffffff'>%1$s</font>", actionBar.getTitle());
                        }
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                            actionBar.setTitle(Html.fromHtml(title, 0));
                        } else {
                            //noinspection deprecation
                            actionBar.setTitle(Html.fromHtml(title));
                        }
                    }
                    actionBar.setDisplayHomeAsUpEnabled(true);
                }
                return;
            } catch (Exception glideException) {
                IEr_CustomerlyErrorHandler.sendError(IEr_CustomerlyErrorHandler.ERROR_CODE__GLIDE_ERROR, "Error during Glide loading in FullScreenImage_Activity", glideException);
            }
        }
    }
    this.finish();
}
 
Example 9
Project: GitHub   File: MovieDetailActivity.java   View Source Code Vote up 5 votes
/**
 * toolbar设置
 */
private void setTitleBar() {
    setSupportActionBar(binding.titleToolBar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        //去除默认Title显示
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.drawable.icon_back);
    }
    // 手动设置才有效果
    binding.titleToolBar.setTitleTextAppearance(this, R.style.ToolBar_Title);
    binding.titleToolBar.setSubtitleTextAppearance(this, R.style.Toolbar_SubTitle);

    binding.titleToolBar.setTitle(subjectsBean.getTitle());
    binding.titleToolBar.setSubtitle(String.format("主演:%s", StringFormatUtil.formatName(subjectsBean.getCasts())));

    binding.titleToolBar.inflateMenu(R.menu.movie_detail);
    binding.titleToolBar.setOverflowIcon(ContextCompat.getDrawable(this, R.drawable.actionbar_more));
    binding.titleToolBar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    binding.titleToolBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.actionbar_more:// 更多信息
                    WebViewActivity.loadUrl(MovieDetailActivity.this,mMoreUrl,mMovieName);
                    break;
            }
            return false;
        }
    });
}
 
Example 10
Project: item-reaper   File: ItemsActivity.java   View Source Code Vote up 5 votes
@Override
public void configureSupportActionBar(Toolbar toolbar, Drawable icon) {
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(icon);
    }
    mDialogOpen = true;
}
 
Example 11
Project: Pluto-Android   File: PlutoActivity.java   View Source Code Vote up 5 votes
/** 设置ActionBar左上角图标 */
protected void setHomeAsUpIndicator(@DrawableRes int resId) {
	ActionBar actionBar = getSupportActionBar();
	if (actionBar != null) {
		actionBar.setHomeAsUpIndicator(resId);
	}
}
 
Example 12
Project: EasyTodo   File: MotiveActivity.java   View Source Code Vote up 5 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_motive);
    Toolbar toolbar = (Toolbar) findViewById(R.id.theme_toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar!=null){
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.drawable.title_back);
    }

    initView();
}
 
Example 13
Project: Swap   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent Startservice=new Intent(this, SearchService.class);
    startService(Startservice);


    SharedPreferences prefs=getSharedPreferences("user", Context.MODE_PRIVATE);
    editor=prefs.edit();
    boolean isGuideLoaded=prefs.getBoolean("denglu",false);
    username=prefs.getString("username",null);

    if (!isGuideLoaded){

        Intent intent=new Intent(MainActivity.this,LoginActivity.class);
        startActivity(intent);
        MainActivity.this.finish();
    }

    navView= (NavigationView)findViewById(R.id.nav_view);
     toolbar= (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar=getSupportActionBar();

    if (actionBar!=null){
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.mipmap.gengduo);
        actionBar.setTitle(" ");
    }

    replaceFragment(new ViewPagerFragmwnt());
    List<String> permissionList = new ArrayList<>();
    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        permissionList.add(Manifest.permission.ACCESS_FINE_LOCATION);
    }
    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        permissionList.add(Manifest.permission.READ_PHONE_STATE);
    }
    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }
    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
        permissionList.add(Manifest.permission.CAMERA);
    }
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED){
        permissionList.add(Manifest.permission.READ_CONTACTS);

    }
    if (!permissionList.isEmpty()) {
        String [] permissions = permissionList.toArray(new String[permissionList.size()]);
        ActivityCompat.requestPermissions(MainActivity.this, permissions, 1);
    } else {
        init();
    }


}
 
Example 14
Project: Swift-Braille-Soft-keyboard   File: DotsStyleActivity.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    try {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings_dots_style);

        //Show back button
        ActionBar ab = getSupportActionBar();
        if (ab != null) {
            ab.setDisplayHomeAsUpEnabled(true);
            ab.setHomeAsUpIndicator(R.mipmap.ic_arrow_back_white_24dp);
        }

        //Speak the title of the activity
        Common.defaultTextSpeech.speechText(getString(R.string.dot_style));

        //Buttons declaration
        dotFillColor = (Button) findViewById(R.id.dotFillColor);
        previousDotFillColor = Common.dotFillColor;
        dotFillColor.setBackgroundColor(previousDotFillColor);
        dotStrokeColor = (Button) findViewById(R.id.dotStrokeColor);
        previousDotStrokeColor = Common.dotStrokeColor;
        dotStrokeColor.setBackgroundColor(previousDotStrokeColor);
        resetSettingsBtn = (Button) findViewById(R.id.resetSettingsBtn);

        //Spinner declaration
        dotRadiusPortraitSpinner = (Spinner) findViewById(R.id.dotRadiusPortraitSpinner);
        dotRadiusLandscapeSpinner = (Spinner) findViewById(R.id.dotRadiusLandscapeSpinner);

        //Portrait dots radius array list
        int thePortraitDefaultDotRadius = Common.getDefaultDotRadius(0);
        ArrayList<String> portraitDotRadiusList = new ArrayList<>();
        for (int x = Common.MIN_DOT_RADIUS; x <= (thePortraitDefaultDotRadius + 20); x++) {
            portraitDotRadiusList.add(String.format(Locale.getDefault(), "%d", x));
        }

        //Portrait dots radius adapter
        portraitDotRadiusAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, portraitDotRadiusList);
        portraitDotRadiusAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        dotRadiusPortraitSpinner.setAdapter(portraitDotRadiusAdapter);
        dotRadiusPortraitSpinner.setSelection(portraitDotRadiusAdapter.getPosition(String.format(Locale.getDefault(), "%d", Common.getSettingInt("dotRadius", thePortraitDefaultDotRadius))), true);

        //Landscape dots radius array list
        int theLandscapeDefaultDotRadius = Common.getDefaultDotRadius(1);
        ArrayList<String> landscapeDotRadiusList = new ArrayList<>();
        for (int x = Common.MIN_DOT_RADIUS; x <= (theLandscapeDefaultDotRadius + 20); x++) {
            landscapeDotRadiusList.add(String.format(Locale.getDefault(), "%d", x));
        }

        //Landscape dots radius adapter
        landscapeDotRadiusAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, landscapeDotRadiusList);
        landscapeDotRadiusAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        dotRadiusLandscapeSpinner.setAdapter(landscapeDotRadiusAdapter);
        dotRadiusLandscapeSpinner.setSelection(landscapeDotRadiusAdapter.getPosition(String.format(Locale.getDefault(), "%d", Common.getSettingInt("dotLandscapeRadius", theLandscapeDefaultDotRadius))), true);

        //Switches declaration
        fillDotOnTouch = (CheckBox) findViewById(R.id.fillDotOnTouch);
        fillDotOnTouch.setChecked(Common.fillDotOnTouch);
        fillDotOnTouch.setOnCheckedChangeListener(this);
        viewBrailleDotNumber = (CheckBox) findViewById(R.id.viewBrailleDotNumber);
        viewBrailleDotNumber.setChecked(Common.viewBrailleDotNumber);

        //Add listeners to spinners
        initListeners(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 15
Project: CoordinatorLayoutExample-master   File: DrawLayoutSample.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_view);

    mToolbar = (Toolbar) findViewById(R.id.id_toolbar);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.activity_navigation);
    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    //<activity android:name=".NavigationActivity" android:theme="@style/AppThemeNoActionBar"></activity>  
    //<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">  
    //初始化toolbar,这里得使用NoActionBar的主题,使用ToolBar替换系统自带的ActionBar达到自己的需求  
    setSupportActionBar(mToolbar);
    ActionBar actionBar = getSupportActionBar();
    //关联图标和侧滑栏  
    actionBar.setHomeAsUpIndicator(R.drawable.menu);
    //设置actionBar和侧滑栏关联  
    actionBar.setDisplayHomeAsUpEnabled(true);
    //初始化drawerlayout和navigationview  
    if (mNavigationView != null) {
        //设置监听回调  
        mNavigationView.setNavigationItemSelectedListener(new NavigationView
                .OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                //根据选中不同的选项来进行不同的操作  
                switch (item.getItemId()) {
                    case R.id.nav_home:
                        getSupportFragmentManager().beginTransaction().replace(R.id.content,
                                ItemFragement.newInstance("主页")).commit();
                        mToolbar.setTitle("主页");
                        break;
                    case R.id.nav_friends:
                        getSupportFragmentManager().beginTransaction().replace(R.id.content,
                                ItemFragement.newInstance("我的好友")).commit();
                        mToolbar.setTitle("我的好友");
                        break;
                    case R.id.nav_discussion:
                        getSupportFragmentManager().beginTransaction().replace(R.id.content, 
                                ItemFragement.newInstance("热文论坛")).commit();
                        mToolbar.setTitle("热文论坛");
                        break;
                    case R.id.nav_messages:
                        getSupportFragmentManager().beginTransaction().replace(R.id.content,
                                ItemFragement.newInstance("我的消息")).commit();
                        mToolbar.setTitle("我的消息");
                        break;
                    case R.id.sub1:
                        getSupportFragmentManager().beginTransaction().replace(R.id.content,
                                ItemFragement.newInstance("子项1")).commit();
                        mToolbar.setTitle("子项1");
                        break;
                    case R.id.sub2:
                        getSupportFragmentManager().beginTransaction().replace(R.id.content,
                                ItemFragement.newInstance("子项2")).commit();
                        mToolbar.setTitle("子项2");
                        break;
                }
                //设置选项选中效果  
                item.setChecked(true);
                //选了侧边栏选项之后,关闭侧边栏  
                mDrawerLayout.closeDrawers();
                //这里返回true有选中的效果,源码中有解释  
                return true;
            }
        });
    }

}
 
Example 16
Project: android-design-library-master   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Adding Toolbar to Main screen
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Setting ViewPager for each Tabs
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);
    // Set Tabs inside Toolbar
    TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
    tabs.setupWithViewPager(viewPager);
    // Create Navigation drawer and inlfate layout
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    // Adding menu icon to Toolbar
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        VectorDrawableCompat indicator
                = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu, getTheme());
        indicator.setTint(ResourcesCompat.getColor(getResources(),R.color.white,getTheme()));
        supportActionBar.setHomeAsUpIndicator(indicator);
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }
    // Set behavior of Navigation drawer
    navigationView.setNavigationItemSelectedListener(
            new NavigationView.OnNavigationItemSelectedListener() {
                // This method will trigger on item Click of navigation menu
                @Override
                public boolean onNavigationItemSelected(MenuItem menuItem) {
                    // Set item in checked state
                    menuItem.setChecked(true);

                    // TODO: handle navigation

                    // Closing drawer on item click
                    mDrawerLayout.closeDrawers();
                    return true;
                }
            });
    // Adding Floating Action Button to bottom right of main view
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Snackbar.make(v, "Hello Snackbar!",
                    Snackbar.LENGTH_LONG).show();
        }
    });
}
 
Example 17
Project: TrackPlan-app   File: Main99Activity.java   View Source Code Vote up 4 votes
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main99);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        ActionBar actionBar=getSupportActionBar();
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.drawable.ic_arrow_back_black_24dp);
        actionBar.setDisplayShowHomeEnabled(true);
        stringArrayList= new ArrayList<String>();

        DesertPlaceholder desertPlaceholder = (DesertPlaceholder) findViewById(R.id.placeholder);
        desertPlaceholder.setOnButtonClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // do stuff

            }
        });



        listView=(ListView) findViewById(R.id.listView65);

        checkdata();
        lviewAdapter=new ListViewAdapterAttendance(this,stringArrayList);
        listView.setAdapter(lviewAdapter);
        TextView t=(TextView)findViewById(R.id.textView59);
if(lviewAdapter.isEmpty())
{t.setVisibility(View.INVISIBLE);
   desertPlaceholder.setVisibility(View.VISIBLE);
}
else {
    desertPlaceholder.setVisibility(View.GONE);
t.setVisibility(View.VISIBLE);
}







    }
 
Example 18
Project: GitHub   File: TasksActivity.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tasks_act);

    // Set up the toolbar.
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar ab = getSupportActionBar();
    ab.setHomeAsUpIndicator(R.drawable.ic_menu);
    ab.setDisplayHomeAsUpEnabled(true);

    // Set up the navigation drawer.
    mDrawerLayout = findViewById(R.id.drawer_layout);
    mDrawerLayout.setStatusBarBackground(R.color.colorPrimaryDark);
    NavigationView navigationView = findViewById(R.id.nav_view);
    if (navigationView != null) {
        setupDrawerContent(navigationView);
    }

    TasksFragment tasksFragment =
            (TasksFragment) getSupportFragmentManager().findFragmentById(R.id.contentFrame);
    if (tasksFragment == null) {
        // Create the fragment
        tasksFragment = TasksFragment.newInstance();
        ActivityUtils.addFragmentToActivity(
                getSupportFragmentManager(), tasksFragment, R.id.contentFrame);
    }

    // Create the presenter
    mTasksPresenter = new TasksPresenter(
            Injection.provideTasksRepository(getApplicationContext()),
            tasksFragment,
            Injection.provideSchedulerProvider());

    // Load previously saved state, if available.
    if (savedInstanceState != null) {
        TasksFilterType currentFiltering =
                (TasksFilterType) savedInstanceState.getSerializable(CURRENT_FILTERING_KEY);
        mTasksPresenter.setFiltering(currentFiltering);
    }
}
 
Example 19
Project: MaterialLearning   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    statusView = initStatusBar();

    NavigationView navView = findViewById(R.id.nav_view);
    mDrawerLayout = findViewById(R.id.drawer_layout);//导航抽屉

    //初始化tab和ViewPager
    initTabViewPager();

    //设置默认选中菜单项
    navView.setCheckedItem(R.id.call);
    //给导航抽屉的选项设置点击监听器
    navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.mail:
                    sentMessage();
                    break;

                case R.id.group:
                    Intent intent = new Intent(MainActivity.this, WeTalkActivity.class);
                    startActivity(intent);
                    break;

                case R.id.call:
                    Intent intent1 = new Intent(Intent.ACTION_DIAL);
                    intent1.setData(Uri.parse("tel:1008611"));
                    startActivity(intent1);
                    break;

                case R.id.callCM:
                    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                        requestPermissionDialog();
                    } else {
                        call();
                    }
                    break;
                case R.id.location:
                    Intent intent5 = new Intent(MainActivity.this, BaiduMapActivity.class);
                    startActivity(intent5);
                    break;

                case R.id.task:
                    Intent intent2 = new Intent(MainActivity.this, DownloadTaskActivity.class);
                    startActivity(intent2);
                    break;

                default:
                    break;
            }

            mDrawerLayout.closeDrawers();
            return true;
        }
    });


    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//设置toolbar
    //设置toolbar上的汉堡菜单
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_black_24dp);
    }

}
 
Example 20
Project: NUI_Project   File: PlaylistActivity.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.playlist_act);

    // Set up the toolbar.
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar ab = getSupportActionBar();
    ab.setHomeAsUpIndicator(R.drawable.ic_menu);
    ab.setDisplayHomeAsUpEnabled(true);

    // Set up the navigation drawer.
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setStatusBarBackground(R.color.colorPrimaryDark);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        setupDrawerContent(navigationView);
    }

    PlaylistFragment playlistFragment =
            (PlaylistFragment) getSupportFragmentManager().findFragmentById(R.id.contentFrame);
    if (playlistFragment == null) {
        // Create the fragment
        playlistFragment = PlaylistFragment.newInstance();
        ActivityUtils.addFragmentToActivity(
                getSupportFragmentManager(), playlistFragment, R.id.contentFrame);
    }

    // Create the presenter
    mPlaylistPresenter = new PlaylistPresenter(
            Injection.provideUseCaseHandler(),
            playlistFragment,
            Injection.provideGetTasks(getApplicationContext())
            );

    // Load previously saved state, if available.
    if (savedInstanceState != null) {
        PlaylistFilterType currentFiltering =
                (PlaylistFilterType) savedInstanceState.getSerializable(CURRENT_FILTERING_KEY);
        mPlaylistPresenter.setFiltering(currentFiltering);
    }

    askForPermission();
}