TollBar设置
程序员文章站
2022-06-19 08:23:09
...
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private Toolbar mToob;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToob = findViewById(R.id.toob);
mToob.setLogo(R.mipmap.ic_launcher);
setSupportActionBar(mToob);
mToob.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()){
case R.id.bar1:
Toast.makeText(MainActivity.this,"Bar11点击",Toast.LENGTH_SHORT).show();
return true;
case R.id.bar2:
Toast.makeText(MainActivity.this,"Bar22点击",Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menus,menu);
return super.onCreateOptionsMenu(menu);
}
}
<android.support.v7.widget.Toolbar
android:id="@+id/toob"
android:layout_width=“match_parent”
android:background="#FF0"
android:layout_height=“wrap_content”>
</android.support.v7.widget.Toolbar>
下一篇: CSS3实现三角形不断放大效果