Android创建Menu菜单
今天本文将为大家介绍Android创建Menu菜单的内容,Android创建Menu菜单是最基本的操作技巧,希望大家可以好好学习。
具体方法如下:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class TestandroidActivity extends Activity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId())
{
case R.id.settings:
startActivity(new Intent(this,com.test.Settings.class));
return true;
}
return false;
}
}
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class Settings extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
}
相关配置文件如下:
以上就是Android创建Menu菜单,希望本文所述对大家的Android程序设计有所帮助,更多精彩内容就在爱站技术频道。
下一篇:Android怎么实现弹出键盘