Android創(chuàng)建Menu菜單實(shí)例
本文實(shí)例講述了Android創(chuàng)建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);
}
}
相關(guān)配置文件如下:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference android:key="music" android:summary="@string/music_summary" android:defaultValue="true" android:title="@string/music_title"/>
<CheckBoxPreference android:key="hints" android:summary="@string/hints_summary" android:title="@string/hints_title"/>
</PreferenceScreen>
希望本文所述對大家的Android程序設(shè)計有所幫助。
相關(guān)文章
Android編程開發(fā)之EditText實(shí)現(xiàn)輸入QQ表情圖像的方法
這篇文章主要介紹了Android編程開發(fā)之EditText實(shí)現(xiàn)輸入QQ表情圖像的方法,涉及Android多媒體文件及EditText的相關(guān)操作技巧,需要的朋友可以參考下2015-12-12Android獲取手機(jī)位置的實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了Android獲取手機(jī)位置的實(shí)現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11Android使用MediaRecorder類進(jìn)行錄制視頻
這篇文章主要介紹了Android使用MediaRecorder類進(jìn)行錄制視頻的相關(guān)資料,需要的朋友可以參考下2015-10-10flutter InkWell實(shí)現(xiàn)水波紋點(diǎn)擊效果
這篇文章主要為大家詳細(xì)介紹了flutter InkWell實(shí)現(xiàn)水波紋點(diǎn)擊效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-07-07