android - 如何在android菜单中同时显示图标和标题

标签 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>

这是我的 Activity ,我正在扩展 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);
    }
}

但标题只在横屏显示

最佳答案

使用 app:showAsAction="ifRoom|withText" 代替 app:showAsAction="always|withText"

getSupportActionBar().setIcon(R.drawable.Your_Icon);

关于android - 如何在android菜单中同时显示图标和标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32203724/

相关文章:

java - 我无法从 AsyncTask 获得结果?

android - 选择时的操作栏菜单项背景

.htaccess - 如何重写 .htaccess 中菜单项的 URL

android - 如何更改 Lollipop 之前和 Lollipop 版本的工具栏菜单项文本颜色

android - 无法实例化应用程序 java.lang.ClassNotFoundException。未在路径 : DexPathList 上找到类 "Application"

Java BigDecimal 与 Android BigDecimal

Android TextView 文本对齐

java - eclipse.ui.menus 的名称过滤器

css - Opera 浏览器显示菜单 (css) 在线和本地不同

jquery - 单击菜单上的 Bootstrap 向上滚动,单击时