如何在工具栏的图标和标题之间设置间距

3
当我选择 item 时,我正在尝试更改 Toolbar 的图标。已经实现了这个功能,但是标题和图标像这张图片一样紧密地挨在一起。我想在它们之间设置空格,请问有什么建议吗?

enter image description here

   public boolean onNavigationItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.Fragment_art) {
        final String art = "<font color='#ffd159'>Art</font>";
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setIcon(R.mipmap.art);
        setTitle(Html.fromHtml(" Wallpapers : "+art));
    } else if (id == R.id.Fragment_Material) {
        final String Material = "<font color='#4acfd9'>Material</font>";
        setTitle(Html.fromHtml(" Wallpapers : "+Material));
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setIcon(R.mipmap.material);

    } else if (id == R.id.Fragment_Natural) {
        final String Natural = "<font color='#49a010'>Natural</font>";
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setIcon(R.mipmap.natural);
        setTitle(Html.fromHtml(" Wallpapers : "+Natural));
    } else if (id == R.id.Fragment_Animal) {
        final String Animal = "<font color='#e76541'>Animal</font>";
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setIcon(R.mipmap.animal);
        setTitle(Html.fromHtml("Wallpapers : "+Animal));
        }

一个像这样的技巧:" 壁纸"。 :) - TuyenNTA
我已经尝试过这个,但是没有起作用。 - MrMR
1个回答

4
尝试使用以下代码:setTitle(Html.fromHtml("&nbsp;壁纸:" + art)); 其中art是与壁纸相关的内容。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接