2 つのアクション バーを作成する必要があります。ちなみに actionBarSherlock を使用しています。したがって、私が正確に必要としているのは、通常のアクションバーの上に「ようこそ画面」のトグルを配置し、通常の ActionBar アクションオプションを 2 つ追加することです。私が必要としているのと同様に、ここのような Gmail とマップです: http://cdn.androidcommunity.com/wp-content/uploads/2012/03/Screenshot_2012-03-28-12-58-16.png評判が低いため画像を投稿させてください。リンクを参照してください)
このマップ アプリには上下にアクション バーがあり、まさに私が必要としているものです。
私はこのトピックについて約 1 週間検索し、いくつかの同様の質問を見つけましたが、回答のどれも理解できませんでした。答えは、私が(まったく)慣れていないカスタムビューに関するもので、物事を理解できませんでしたが、はい、私が正しいと思ったものから「カスタムビュー」を作成しようとしましたが、私はしませんでした解決策が見つかりません...例として、このマップアプリを見せていただければ、これら2つのアクションバーをどのように使用していますか?? (マップや gmail のようにナビゲートしたくありませんが、2 つのアクションバーのみ)
これが私のコードの一部です:
//Part of my MainActivity.class
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
MenuInflater inf = getSupportMenuInflater();
inf.inflate(R.menu.upper_navbar, menu);
final String name = "welcome";
final SharedPreferences pref = getSharedPreferences(name, 0);
final Editor edit = pref.edit();
boolean oldState = pref.getBoolean("w", true);
ToggleButton tog = (ToggleButton) menu.findItem(R.id.welcome_screen).getActionView();
if(oldState){
tog.setChecked(true);
}else{
tog.setChecked(false);
}
tog.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
edit.putBoolean("w", true);
edit.apply();
}else{
edit.putBoolean("w", false);
edit.apply();
}
}
});
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
私のマニフェスト:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="seaskyways.editpad"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:name="android.app.Application"
android:icon="@drawable/ic_launcher"
android:uiOptions="splitActionBarWhenNarrow"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="seaskyways.editpad.MainActivity"
android:label="MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="seaskyways.editpad.Splash"
android:theme="@style/Theme.Sherlock.Dialog.NoActionBar"
android:label="Splash" >
<intent-filter>
<action android:name="android.intent.action.SPLASH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
そして、アクションバーに配置する予定のメニュー...
menu\activity_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/bottom_copy" android:title="Copy" android:orderInCategory="3" android:showAsAction="ifRoom|withText" />
<item android:id="@+id/bottom_paste" android:title="Paste" android:orderInCategory="2" android:showAsAction="ifRoom|withText" />
</menu>
menu\upper_navbar.xml (upper_actionbar という名前にするべきでしたが、単なる考え違いでした。結局、その名前です :/ 続行してください )
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/welcome_screen"
android:orderInCategory="1"
android:showAsAction="ifRoom|withText"
android:title="Welcome Screen"
android:actionLayout="@layout/toggle"
/>
</menu>
これ以上の情報が必要な場合は、私に教えてください。
編集 !!!:私の質問、wifi 設定 ( http://omgdroid.com/wp-content/uploads/2012/07/Screenshot_2012-07-06-01-34-29-576x1024.png ) に通常のアクションバーでスイッチを使用し、通常の分割アクションバーを下に ! まさに私が必要なもの!
編集2!!!! : これは aosp ベースのカスタム ROM を使用した私の Galaxy nexus のスクリーンショットです。
設定-Bluetooth: lh3*googleusercontent.com/-4j6ca1Nm1VI/UPVqAiDn_PI/AAAAAAAAAGM/LLB2ILWVjQY/s512/Screenshot_2013-01-15-16-38-14.png
編集 3 !!! : Bluetooth と Wifi に関する私の調査は大きく進歩しました。Settings-Bluetooth で得たものを参照してください。
BluetoothSettings.class/onCreateOptionsMenu :
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if (mLocalAdapter == null) return;
boolean bluetoothIsEnabled = mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON;
boolean isDiscovering = mLocalAdapter.isDiscovering();
int textId = isDiscovering ? R.string.bluetooth_searching_for_devices :
R.string.bluetooth_search_for_devices;
menu.add(Menu.NONE, MENU_ID_SCAN, 0, textId)
.setEnabled(bluetoothIsEnabled && !isDiscovering)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(Menu.NONE, MENU_ID_RENAME_DEVICE, 0, R.string.bluetooth_rename_device)
.setEnabled(bluetoothIsEnabled)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.add(Menu.NONE, MENU_ID_VISIBILITY_TIMEOUT, 0, R.string.bluetooth_visibility_timeout)
.setEnabled(bluetoothIsEnabled)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.add(Menu.NONE, MENU_ID_SHOW_RECEIVED, 0, R.string.bluetooth_show_received_files)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
super.onCreateOptionsMenu(menu, inflater);
}
これらのオプションは、正確なプロパティを使用して splitActionBarDown に明確に表示されます...
今 :
BluetoothSettings.class/addPreferencesForActivity :
@Override
void addPreferencesForActivity() {
addPreferencesFromResource(R.xml.bluetooth_settings);
Activity activity = getActivity();
Switch actionBarSwitch = new Switch(activity);
if (activity instanceof PreferenceActivity) {
PreferenceActivity preferenceActivity = (PreferenceActivity) activity;
if (preferenceActivity.onIsHidingHeaders() || !preferenceActivity.onIsMultiPane()) {
final int padding = activity.getResources().getDimensionPixelSize(
R.dimen.action_bar_switch_padding);
actionBarSwitch.setPadding(0, 0, padding, 0);
activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
ActionBar.DISPLAY_SHOW_CUSTOM);
activity.getActionBar().setCustomView(actionBarSwitch, new ActionBar.LayoutParams(
ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_VERTICAL | Gravity.END));
}
}
mBluetoothEnabler = new BluetoothEnabler(activity, actionBarSwitch);
setHasOptionsMenu(true);
}
このクラスは Activity を拡張していないことに注意してくださいextends DeviceListPreferenceFragment
。
2 つのアクションバー (スプリットとノーマル) を同時に持つことができることがわかったので、おそらくクラスまたはライブラリによって、それを単純化する方法が必要です ??