アクションバーにドロップダウン/プルダウンシークバーを配置しようとしています。私はこのようなものがうまくいくと思ったOnCreateOptionsMenu()
:
SubMenu subMenu = menu.addSubMenu("DropTest");
MenuItem seekBarDrop = subMenu2.add("SeekBar");
SeekBar seekBar = new SeekBar(this);
seekBarDrop.setActionView(seekBar);
seekBarDrop.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
MenuItem subMenuItem = subMenu2.getItem();
subMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
しかし、それは惨めに失敗します。また、スピナーアダプターにハッキングしようとしました(actionbarsherlockにIcsSpinnerを使用):
ArrayAdapter<CharSequence> seekAdapter =
new ArrayAdapter<CharSequence>(context,
R.layout.spinner_subtitled_octave,
android.R.id.text1, new String[]{""});
seekAdapter.setDropDownViewResource(R.layout.seekbar);
MenuItem itemX = menu.add("SeekBar").setActionView(R.layout.spinner_ics);
itemX.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
IcsSpinner spinBar = (IcsSpinner) itemX.getActionView();
spinBar.setAdapter(seekAdapter);
/*
* This next part doesn't crash, but it also doesn't work
*/
LinearLayout sbLayout = (LinearLayout)
seekAdapter.getDropDownView(0, null, null);
SeekBar seekBar = (SeekBar) sbLayout.findViewById(R.id.v_seekbar);
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
Log.d(TAG, "" + progress); // nope
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) { }
@Override
public void onStopTrackingTouch(SeekBar seekBar) { }
});
とseekbar.xml
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/highlight"
/>
<SeekBar
android:id="@+id/v_seekbar"
android:minWidth="100dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/spacer" />
</LinearLayout>
そして spinner_seek.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/TextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SEEKBAR"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/main" />
<TextView
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/highlight" />
</LinearLayout>
少なくともドロップダウンへのシークバーを取得しますが、それへの参照を取得する方法がわかりません。
ラストマイルの行き方を知っている人はいますか?
編集: 存在することを書いた後に気付きましたPopupMenu
が、それは API 11+ (私のプロジェクトは 10+) または HoloEverywhere のみです。ABS以外のライブラリなしでこれを行うことを望んでいます。