【问题标题】:drop down menu on image button on action bar操作栏上图像按钮上的下拉菜单
【发布时间】:2014-06-17 18:31:44
【问题描述】:

我有一个操作栏..我只有一个徽标和一个图像按钮,当我按下按钮时,我想要一个带有三个值的微调器,每个都打开一个新活动,这是我的代码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    android.app.ActionBar mActionBar = getActionBar();
    mActionBar.setDisplayShowHomeEnabled(false);
    mActionBar.setDisplayShowTitleEnabled(false);
    LayoutInflater mInflater = LayoutInflater.from(this);

    View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
    TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
    mTitleTextView.setText("My Own Title");

    ImageButton imageButton = (ImageButton) mCustomView
            .findViewById(R.id.imageButton);
    imageButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
     // i want the spinner to be add here 
        }
    });

    mActionBar.setCustomView(mCustomView);
    mActionBar.setDisplayShowCustomEnabled(true);
}

@Override
public boolean onNavigationItemSelected(int arg0, long arg1) {
    // TODO Auto-generated method stub
    return false;
} 

【问题讨论】:

    标签: android android-actionbar spinner


    【解决方案1】:

    公共类 MainActivity 扩展 Activity{ ... ...

    /**
     * On selecting action bar icons
     * */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Take appropriate action for each action item click
        switch (item.getItemId()) {
        case R.id.action_search:
            // search action
            return true;
        case R.id.action_location_found:
            // location found
            LocationFound();
            return true;
        case R.id.action_refresh:
            // refresh
            return true;
        case R.id.action_help:
            // help action
            return true;
        case R.id.action_check_updates:
            // check for updates action
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }
    
    /**
     * Launching new activity
     * */
    private void LocationFound() {
        Intent i = new Intent(MainActivity.this, LocationFound.class);
        startActivity(i);
    }
    

    }

    试试这个代码:

    为了更好地理解,请通过以下链接 http://www.androidhive.info/2013/11/android-working-with-action-bar/

    【讨论】:

    • 这是一个不从图像按钮开始的微调器 .. 它只是一个具有 3 值的微调器,第一个值将始终显示 .. 那我该怎么做呢?跨度>
    • 我已更改代码...立即尝试...请通过此 lnk androidhive.info/2013/11/android-working-with-action-bar
    • 你只是在复制代码..这不是我需要的
    • 从该链接下载项目...您将了解所有详细信息
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多