汇总常用的或者经常忘记的Android控件
DrawerLayout
弹出式抽屉视图
DrawerLayout 控件的子视图必须是2个,1个显示原视图,1个显示弹出的抽屉视图
1 | <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" |
硬按键控制音量
1 添加权限<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
2 新建控制音量类实例
1 | //音量控制,初始化定义 |
3 实例初始化,在onCreat()
中:
1 | mAudioManager = (AudioManager) |
4 具体调节音量
1 | @Override |
home按键切换后台
1借用surface改变:
切换后台触发:
1 | public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) { |
回到前台触发:
1 | public void surfaceCreated(SurfaceHolder arg0) { //activity resume |
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aty_securityissue_creat);
actionBar= getActionBar();
actionBar.show();
}1
2
3
//创建菜单
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
super.onCreateOptionsMenu(menu);
//添加菜单项
MenuItem add=menu.add(0,0,0,”add”);
MenuItem del=menu.add(0,0,0,”del”);
MenuItem save=menu.add(0,0,0,”save”);
//绑定到ActionBar
add.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
del.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
save.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true;
}
//选择菜单
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case android.R.id.home:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
```