- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试在操作栏中放置一个下拉/下拉搜索栏。我认为 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);
但它惨遭失败。我也试过将它改造成微调器适配器(使用 IcsSpinner 来实现 actionbarsherlock):
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 以外的任何库的情况下做到这一点。
最佳答案
这是您要找的吗:
我使用 BaseAdapter 做了这个:
主要 Activity :
public class MainActivity extends Activity implements OnNavigationListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar bar = getActionBar();
ArrayList<String> list = new ArrayList<String>();
list.add("bar 0 ");
list.add("bar 2 ");
list.add("bar 3 ");
list.add("bar 4 ");
Adapter adapter = new Adapter();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
bar.setListNavigationCallbacks(adapter.getAdapter(this, list, "Controls"), this);
adapter.setSeekBarListener( new SeekBarListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser, int positionInList) {
Log.i("", "onProgressChanged " + progress + " position in list" + positionInList);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar, int positionInList) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar, int positionInList) {
// TODO Auto-generated method stub
}
});
}
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
// TODO Auto-generated method stub
return false;
}
适配器类:
public class Adapter {
private SeekBarListener mListener;
public interface SeekBarListener{
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser, int positionInList);
public void onStartTrackingTouch(SeekBar seekBar, int positionInList);
public void onStopTrackingTouch(SeekBar seekBar, int positionInList);
}
public listAdapter getAdapter(Context context, ArrayList<String> list, String title){
return new listAdapter(context, list, title);
}
public void setSeekBarListener(SeekBarListener listener){
mListener = listener;
}
public class listAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private onSeekbarChange mSeekListener;
private ArrayList<String> itemsList;
private String title;
public listAdapter(Context context, ArrayList<String> list, String title){
mInflater = LayoutInflater.from(context);
if(mSeekListener == null){
mSeekListener = new onSeekbarChange();
}
this.itemsList = list;
this.title = title;
}
@Override
public int getCount() {
return itemsList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder2 holder;
if(convertView == null){
holder = new ViewHolder2();
convertView = mInflater.inflate(R.layout.baseadapter_layout, null);
holder.text_title = (TextView)convertView.findViewById(R.id.textView);
convertView.setTag(R.layout.baseadapter_layout, holder);
} else {
holder = (ViewHolder2)convertView.getTag(R.layout.baseadapter_layout);
}
holder.text_title.setText(title);
return convertView;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null){
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.baseadapter_dropdown_layout, null);
holder.text = (TextView)convertView.findViewById(R.id.textView1);
holder.seekbar = (SeekBar)convertView.findViewById(R.id.seekBar1);
convertView.setTag(R.layout.baseadapter_dropdown_layout, holder);
} else {
holder = (ViewHolder)convertView.getTag(R.layout.baseadapter_dropdown_layout);
}
holder.text.setText(itemsList.get(position));
holder.seekbar.setOnSeekBarChangeListener(mSeekListener);
holder.seekbar.setTag(position);
return convertView;
}
}
static class ViewHolder {
TextView text;
SeekBar seekbar;
}
static class ViewHolder2 {
TextView text_title;
}
public class onSeekbarChange implements OnSeekBarChangeListener{
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int position = (Integer) seekBar.getTag();
if(mListener != null){
mListener.onProgressChanged(seekBar, progress, fromUser, position);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
int position = (Integer) seekBar.getTag();
if(mListener != null){
mListener.onStartTrackingTouch(seekBar, position);
}
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
int position = (Integer) seekBar.getTag();
if(mListener != null){
mListener.onStopTrackingTouch(seekBar, position);
}
}
}
baseadapter_layout.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="25dp"
android:layout_marginTop="18dp"
android:textColor="#FFFFFF"
android:text="Controls" />
baseadapter_dropdown_layout.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:textColor="#FFFFFF"
android:text="TextView" />
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="11dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_toRightOf="@+id/textView1" />
关于android - 在 Android 操作栏中下拉搜索栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17407754/
我在让我的操作栏显示图标时遇到问题。它显示了我在溢出菜单中设置的文本/标题(三个点),但没有任何操作。这是我的代码,我错过了什么? MainActivity.java public class Mai
我正在尝试在 android 中制作一个动态操作栏,现在我正在尝试像这样在操作栏中进行搜索。 http://developer.android.com/images/ui/actionbar-sear
我正在编写 uiautomator 测试,但我很难弄清楚如何单击我的操作栏图标。 如果我的操作是“始终”显示,则很容易找到并点击。 如果我的操作是显示“从不”,我必须单击菜单,然后从菜单中单击。先点击
我有一个正在寻找特定 URI 的重写规则。当它匹配特定的 URL 时,它会使用正确的文件路径重写它,以便可以找到所需的内容。然后它将协议(protocol)更改为 HTTPS 并允许请求通过。 我有两
我正在为 android 中的 ActionBar 而苦苦挣扎。 这是我的问题:我的操作项没有显示在操作栏中,而是堆叠在操作溢出中,无论我做什么.. 我花了一天的时间寻找解决方案,但我似乎找不到缺少的
我的网络应用程序在 Tomcat 下运行,它非常密集地使用 AJAX 请求,在开发过程中我也必须密集地重新部署网络应用程序。重新部署后,我通常会简单地刷新页面,知道用户 session 已删除,但我总
我是一名优秀的程序员,十分优秀!