一个简单的toolabar结合drawlayout使用方法

本文实例为大家分享了toolabar结合drawlayout使用方法,供大家参考,具体内容如下

package alice.bw.com.day03toolabardrawlayout;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Toast;

/**
 * ToolaBar的使用
 */
public class ToolBarBaseActivity extends AppCompatActivity {
 private Toolbar mToolbar;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  supportRequestWindowFeature(Window.FEATURE_NO_TITLE);//如果继承的是AppCompatActivity 使用supportRequestWindowFeature(Window.FEATURE_NO_TITLE)
  //如果继承的Activity使用requestWindowFeature(Window.FEATURE_NO_TITLE);,必须要在setContentView之前
  setContentView(R.layout.activity_tool_bar_base);
  mToolbar = (Toolbar) findViewById(R.id.toolaBar);
  //设置ToolBar的导航图标
  mToolbar.setNavigationIcon(R.mipmap.ic_launcher);
  mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View view) {
    Toast.makeText(ToolBarBaseActivity.this, "我是导航图标", Toast.LENGTH_SHORT).show();
   }
  });
  //设置logo
  mToolbar.setLogo(R.mipmap.ic_launcher);
  mToolbar.setTitle("大标题");
  mToolbar.setSubtitle("子标题");
  //设置menu
  mToolbar.inflateMenu(R.menu.toolbarmenu);
  mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
   @Override
   public boolean onMenuItemClick(MenuItem item) {
    switch (item.getItemId()){
     case R.id.item_1:
      Toast.makeText(ToolBarBaseActivity.this, "标题一", Toast.LENGTH_SHORT).show();
      break;
     case R.id.item_2:
      Toast.makeText(ToolBarBaseActivity.this, "标题二", Toast.LENGTH_SHORT).show();
      break;
     case R.id.item_3:
      Toast.makeText(ToolBarBaseActivity.this, "标题三", Toast.LENGTH_SHORT).show();
      break;
    }

    return true;
   }
  });
 }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: