如何在Android菜单中显示图标和标题

时间:2015-08-25 12:12:56

标签: android menu menuitem

我想知道如何在Android菜单中显示图标和标题。

我用这个:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.yasser.version6.NewprofileActivity">


    <item
        android:id="@+id/action_done"
        android:title="SUIVANT"
        android:orderInCategory="100"
        android:icon="@drawable/ic_action_done"
        app:showAsAction="always|withText" />


</menu>

以下是我的活动,我正在扩展AppCompatActivity就好了吗?然后我在我的应用程序中使用自定义工具栏

public class NewprofileActivity extends AppCompatActivity {
    ImageView profil_image;
    Toolbar mToolbar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_newprofile);
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        mToolbar.setTitle("Profil");
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        profil_image=  (ImageView) findViewById(R.id.profil_image);


        Picasso.with(profil_image.getContext()).load(R.drawable.profil_icon).transform(new Imagetransformation()).into(profil_image);
    }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

但标题仅在横向

上显示

1 个答案:

答案 0 :(得分:4)

使用site=list.files(pattern='[.]xls') 代替app:showAsAction="ifRoom|withText"

并且

app:showAsAction="always|withText"