在操作栏上更改微调器导航的位置

时间:2017-01-25 13:06:04

标签: android navigationbar

我有动作栏的应用程序。我试着设置一个真正的ActionBar,但现在它被弃用了。所以我发现了这种方式。但我想将导航微调器移动到操作栏的左侧。如果可能的话? enter image description here

public class MainActivity extends AppCompatActivity {

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

    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        String colors[] = {"MyList","Red","Blue","White","Yellow","Black", "Green","Purple","Orange","Grey"};
        getMenuInflater().inflate(R.menu.android_action_bar_spinner_menu, menu);
        getMenuInflater().inflate(R.menu.menu1,menu);
        MenuItem item = menu.findItem(R.id.spinner);
        Spinner spinner = (Spinner) MenuItemCompat.getActionView(item);
        ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
                android.R.layout.simple_spinner_dropdown_item,colors);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        String msg="";
        switch(item.getItemId()){//selected menu item
            case R.id.first:
               //// Logout();
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}

这就是微调器菜单的样子。

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    >
    <item
        android:id="@+id/spinner"
        android:title="ActionBar Spinner"
        app:actionViewClass="android.widget.Spinner"
        android:background="#ff00"
        app:showAsAction="always"

        android:checkable="false" />
</menu>

0 个答案:

没有答案