微调的操作栏中,只有图标,但没有选择的选择栏中、图标、操作

由网友(流年的顛簸。)分享简介:我的工作与导航操作栏中的应用程序。现在,我想一个微调添加到动作条。我能够得到的动作条我的自定义图标。但是,当我添加条目进入微调,图标背后却隐藏着选择的选择框与第一个项目。 我想有只在动作条和下拉列表/微调出现的图标在图标上挖掘时。这是我的code:私人无效initializeMenu(功能菜单){MenuInflate...

我的工作与导航操作栏中的应用程序。现在,我想一个微调添加到动作条

我能够得到的动作条我的自定义图标。但是,当我添加条目进入微调,图标背后却隐藏着选择的选择框与第一个项目。

我想有只在动作条下拉列表/微调出现的图标在图标上挖掘时。

这是我的code:

 私人无效initializeMenu(功能菜单){
    MenuInflater充气= getMenuInflater();
    inflater.inflate(R.menu.options,菜单);

    视图V =(查看)menu.findItem(R.id.menuSort).getActionView();
    微调微调=(微调)v.findViewById(R.id.bookmarks_menu);

    收藏书签1 =新书签();
    收藏书签2 =新书签();

    名单<书签及GT;名单=新的ArrayList<书签及GT;();
    list.add(书签1);
    list.add(书签2);

    SpinAdapter适配器=新SpinAdapter(getApplicationContext(),0,清单);
    spinner.setAdapter(适配器);
}
 

解决方案 快速栏的 图标不见了怎么办

检查该公司的工作。

 公共类MainActivity延伸活动{

    最终的String []选择= {机器人,iOS的,RIM};
    最终诠释[] choices_img = {R.drawable.ic_launcher,R.drawable.ios,
            R.drawable.black};

    @燮pressLint(NewApi)
    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);

        动作条动作条= getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

        ArrayAdapter<字符串>适配器=新的ArrayAdapter<字符串>(
                MainActivity.this,android.R.layout.simple_dropdown_item_1line,
                选择);
        ListViewAdapter适配器1 =新ListViewAdapter(MainActivity.this);
        actionBar.setListNavigationCallbacks(适配器1,
                新OnNavigationListener(){
                    @覆盖
                    公共布尔onNavigationItemSelected(INT itemPosition,
                            长的itemId){
                        Toast.makeText(MainActivity.this,
                                选择[itemPosition],Toast.LENGTH_SHORT)
                                。显示();
                        返回false;
                    }
                });
    }

    @覆盖
    公共布尔onCreateOptionsMenu(功能菜单){
        //充气菜单;这增加了项目操作栏,如果它是present。
        。getMenuInflater()膨胀(R.menu.main,菜单);
        返回true;
    }

    公共类ListViewAdapter扩展了BaseAdapter {

        私人LayoutInflater mInflater;

        公共ListViewAdapter(上下文CON){
            // TODO自动生成构造函数存根
            mInflater = LayoutInflater.from(CON);
        }

        公众诠释getCount将(){
            // TODO自动生成方法存根
            返回choices.length;
        }

        公共对象的getItem(INT位置){
            // TODO自动生成方法存根
            //返回product_id1.size();
            返回的位置;
        }

        众长getItemId(INT位置){
            // TODO自动生成方法存根
            //返回product_id1.get(位置).hash code();
            返回的位置;
        }

        @燮pressLint(NewApi)
        公共查看getView(最终诠释的立场,观点convertView,
                ViewGroup中父){
            // TODO自动生成方法存根
            最后的listContent持有人;
            视图V = convertView;
            如果(V == NULL){
                V = mInflater.inflate(R.layout.scan_row1,NULL);
                持有人=新的listContent();

                holder.name =(TextView中)v.findViewById(R.id.textView1);

                holder.img_p =(ImageView的)v.findViewById(R.id.imageView1);

                // holder.total_rate.setOnClickListener(mOnTitleClickListener1);

                v.setTag(保持器);
            } 其他 {

                支架=(的listContent)v.getTag();
            }

            holder.img_p.setBackground(getResources()。getDrawable(
                    choices_img [位置]));
            holder.name.setText(+选择[位置]);

            返回伏;
        }
    }

    静态类的listContent {

        ImageView的img_p;
        TextView的名称;

    }

}
 

如果你只想图标,然后只使用在scan_row1.xml图像视图

I am working on a app with action bar for navigation. Now I am trying to add a Spinner to the ActionBar.

I am able to get my custom icon on the ActionBar. But when I add entries into the spinner, the icon is hidden behind the selection box with first item selected.

I want to have only the icon in the ActionBar and the drop-down-list/spinner to appear when tapped on the icon.

This is my code :

private void initializeMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.options, menu);

    View v = (View) menu.findItem(R.id.menuSort).getActionView();
    Spinner spinner=(Spinner)v.findViewById(R.id.bookmarks_menu);

    Bookmark bookmark1 = new Bookmark();
    Bookmark bookmark2 = new Bookmark();

    List<Bookmark> list = new ArrayList<Bookmark>();
    list.add(bookmark1);
    list.add(bookmark2);

    SpinAdapter adapter = new SpinAdapter(getApplicationContext(),0, list);
    spinner.setAdapter(adapter); 
}

解决方案

check this its working..

public class MainActivity extends Activity {

    final String[] choices = { "Android", "iOS", "RIM" };
    final int[] choices_img = { R.drawable.ic_launcher, R.drawable.ios,
            R.drawable.black };

    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                MainActivity.this, android.R.layout.simple_dropdown_item_1line,
                choices);
        ListViewAdapter adapter1 = new ListViewAdapter(MainActivity.this);
        actionBar.setListNavigationCallbacks(adapter1,
                new OnNavigationListener() {
                    @Override
                    public boolean onNavigationItemSelected(int itemPosition,
                            long itemId) {
                        Toast.makeText(MainActivity.this,
                                choices[itemPosition], Toast.LENGTH_SHORT)
                                .show();
                        return false;
                    }
                });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public class ListViewAdapter extends BaseAdapter {

        private LayoutInflater mInflater;

        public ListViewAdapter(Context con) {
            // TODO Auto-generated constructor stub
            mInflater = LayoutInflater.from(con);
        }

        public int getCount() {
            // TODO Auto-generated method stub
            return choices.length;
        }

        public Object getItem(int position) {
            // TODO Auto-generated method stub
            // return product_id1.size();
            return position;
        }

        public long getItemId(int position) {
            // TODO Auto-generated method stub
            // return product_id1.get(position).hashCode();
            return position;
        }

        @SuppressLint("NewApi")
        public View getView(final int position, View convertView,
                ViewGroup parent) {
            // TODO Auto-generated method stub
            final ListContent holder;
            View v = convertView;
            if (v == null) {
                v = mInflater.inflate(R.layout.scan_row1, null);
                holder = new ListContent();

                holder.name = (TextView) v.findViewById(R.id.textView1);

                holder.img_p = (ImageView) v.findViewById(R.id.imageView1);

                // holder.total_rate.setOnClickListener(mOnTitleClickListener1);

                v.setTag(holder);
            } else {

                holder = (ListContent) v.getTag();
            }

            holder.img_p.setBackground(getResources().getDrawable(
                    choices_img[position]));
            holder.name.setText("" + choices[position]);

            return v;
        }
    }

    static class ListContent {

        ImageView img_p;
        TextView name;

    }

}

if you want only icon then just use image view in scan_row1.xml

阅读全文

相关推荐

最新文章