package com.bw.zhuangao2_9;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar=findViewById(R.id.bar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {//点击事件
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "你点击导航图片", Toast.LENGTH_SHORT).show();
}
});
toolbar.inflateMenu(R.menu.menu);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()){
case R.id.one1:
Toast.makeText(MainActivity.this, "卢豪", Toast.LENGTH_SHORT).show();
break;
case R.id.one2:
Toast.makeText(MainActivity.this, "卢管", Toast.LENGTH_SHORT).show();
break;
case R.id.one3:
Toast.makeText(MainActivity.this, "卢艺管", Toast.LENGTH_SHORT).show();
break;
}
return true;
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<androidx.appcompat.widget.Toolbar
android:id="@+id/bar"
app:navigationIcon="@mipmap/ic_launcher"
android:tooltipText="@string/app_name"
android:background="#8BC34A"
app:title="管家军长"
app:subtitle="卢豪"
app:titleTextColor="#009688"
app:subtitleTextColor="@color/colorAccent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"></EditText>
</androidx.appcompat.widget.Toolbar>
</LinearLayout>
package com.bw.zhuangao2_9;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
public class MainActivity2 extends AppCompatActivity {
private DrawerLayout dra;
private ImageView im2;
private ImageView im1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
dra = (DrawerLayout) findViewById(R.id.dra);
im2 = (ImageView) findViewById(R.id.im2);
im1 = (ImageView) findViewById(R.id.im1);
im1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dra.openDrawer(Gravity.LEFT);
}
});
im2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dra.openDrawer(Gravity.LEFT);
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:id="@+id/dra"
tools:context=".MainActivity2">
<LinearLayout
android:layout_gravity="left"
android:background="#E91E63"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/im2"
android:src="@drawable/ic_launcher_background"
android:layout_width="100dp"
android:layout_height="100dp"></ImageView>
</LinearLayout>
<LinearLayout
android:background="#2196F3"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/im1"
android:src="@mipmap/ic_launcher"
android:layout_width="100dp"
android:layout_height="100dp"></ImageView>
</LinearLayout>
</androidx.drawerlayout.widget.DrawerLayout>
package com.bw.zhuangao2_9;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
public class MainActivity3 extends AppCompatActivity {
SlidingMenu slidingMenu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
slidingMenu=new SlidingMenu(this);
slidingMenu.setMode(SlidingMenu.LEFT);
View view= LayoutInflater.from(this).inflate(R.layout.left,null);
ImageView imageView=view.findViewById(R.id.iv4);
slidingMenu.setMenu(view);
slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
slidingMenu.attachToActivity(this,SlidingMenu.SLIDING_CONTENT);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
slidingMenu.showContent();
}
});
}
}