Android開發 更改返回按鈕的表徵圖

來源:互聯網
上載者:User

標籤:android   style   io   ar   java   sp   div   on   cti   

很多的Android應用左上方都有返回按鈕

在預設的情況下 ADT會預設給一個返回表徵圖

而作為開發需求 很多都要求定製一個新的表徵圖

在Android的網站上 發現了2種可以更改的方法


1.

在java代碼環境中設定

actionBar = getActionBar();        actionBar.setDisplayHomeAsUpEnabled(true);        actionBar.setHomeAsUpIndicator(R.drawable.back);


如果有錯誤提示 Call requires API level 18 (current min is 14): android.app.ActionBar#setHomeAsUpIndicator

說明當前的最小API等級低於18  那麼就參考第二種方法了


2.

在styles.xml中新增一種style

<style name="style_titlebar_normal" parent="Theme.AppCompat.Light">       <item name="android:homeAsUpIndicator">@drawable/back</item> <!--返回icon-->    </style>  


然後在AndroidManifest.xml中 在其Activity 的theme中設定成該style


<activity            android:name="com.logic.activity.Activity1"            android:theme="@style/style_titlebar_normal"            >        </activity>

這種方法對API level沒有要求 就是略複雜些







Android開發 更改返回按鈕的表徵圖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.