新しいツールバー コンポーネントを試していますが、ナビゲーション アイコンに問題があります。戻るナビゲーション用のカスタム アイコンを実装したい:
私のマニフェストでは、アクティビティに親を設定します:
<activity android:name=".CardsActivity" android:parentActivityName=".MainActivity">
<!-- Parent activity meta-data to support API level 7+ -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
ツールバーを次のように宣言します。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.lollitest.MainActivity" >
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:layout_marginBottom="10dp"
android:background="?attr/colorPrimary" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/my_awesome_toolbar"
android:text="@string/hello_world" />
</RelativeLayout>
次に、私のアクティビティで、ツールバーを次のように構成します。
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
toolbar.setNavigationIcon(R.drawable.ic_good);
toolbar.setTitle("Title");
toolbar.setSubtitle("Sub");
toolbar.setLogo(R.drawable.ic_launcher);
setSupportActionBar(toolbar);
私に与えるもの:
戻るアイコンは、私が設定したものではありませんsetNavigationIcon()
! メソッドにどのようなドローアブルを指定しても、ナビゲーション アイコンは常に戻る矢印です。
マニフェストで親の関連付けを削除しようとしましたが、唯一の効果は (明らかに) ボタンが戻るのを防ぐことです。
逆に、デフォルトの戻る矢印アイコンが必要で、呼び出しをsetNavigationIcon()
行わない場合、アイコンはまったくありません。
ツールバー (カスタムおよびデフォルト) のナビゲーション アイコンを処理する正しい方法は何ですか?
注:Android 4.4でテストを実行しています