Android ActionBar上不顯示icon的問題

來源:互聯網
上載者:User

Android ActionBar上不顯示icon的問題

又是一個 support library的問題,最近被這個android.support.v4 和android.support.v7 折磨的要死要活的,很多東西因為版本的變動有好多的不同。由於我的項目用了 Fragment的v4 surpport包,所以在Activity繼承ActionBarActivity的時候繼承了v7的,不知道為什麼操作欄上Item的表徵圖就是不顯示。查了查原因

StackOverFlow上的答案。

This is because if you use the support AppCompat ActionBar library and ActionBarActivity you should create your menus in a different than the standard way of creating xml menus in ActioBarSherlock or the default ActionBar.

 

  添加了第二行:

 

 

xmlns:app="http://schemas.android.com/apk/res-auto"
並且把下行的Android:showAsAction="always"改成

 

 

 app:showAsAction="always" 
查了官方文檔也弄的不是很明白,總之是解決了。

 

Android在解決版本相容的問題上真的是很蛋疼。。。怎麼說呢,最近總結的經驗就是一定要Google,最好用英文查,百度一下午不如google幾分鐘解決問題 = =

 

順帶解決一下 不顯示app icon 的問題,查的醉醉的,在activity 的 oncreate 方法加入:

 

ActionBar actionBar = getSupportActionBar();actionBar.setLogo(R.drawable.ic_launcher);actionBar.setDisplayUseLogoEnabled(true);actionBar.setDisplayShowHomeEnabled(true);


 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.