2015-08-25 70 views
0

我想知道如何在android菜單中顯示圖標和標題。如何在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); 
    } 
} 

但標題只顯示景觀

+0

http://stackoverflow.com/a/16754609/3713967 –

+0

你在你的菜單中還能做什麼。可能是因爲沒有空間來顯示兩者,我猜文本會先掉下來。 – StuStirling

+0

我沒有任何東西只有一個項目 –

回答

4

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

而且

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

我得到一個錯誤「應使用app:showAsAction爲appcompat庫 –

+0

@YasserB。立即設置此應用程序:showAsAction =」ifRoom | withText「 –

+0

相同沒有更改,我更新瞭如果你的主題不是更新你的主題,如,那麼你可以看看我的活動 –

相關問題