setDisplayHomeAsUpEnabled 使用样式属性
setDisplayHomeAsUpEnabled using a style attribute
是否可以在使用AppCompatActivity
时指定getSupportActionBar().setDisplayHomeAsUpEnabled(true)
使用样式,而不是以编程方式这样做?
我可以指定可绘制对象本身,但如何使用样式启用它?
<style name="MyActivityTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarTheme">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="homeAsUpIndicator">@drawable/ic_clear</item>
<!-- Enable the above using a style attribute -->
</style>
无法通过 xml 启用它。您只能在清单中设置父项 activity:
<activity
android:name=".CurrentActivity"
android:label="@string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivityy" />
</activity>
但您无法通过 xml 启用它。不管怎样,它只是一行代码。
样式:
<style name="MyActionBarStyle" parent="Widget.AppCompat.Light.ActionBar.Solid">
<item name="displayOptions">showTitle|homeAsUp</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="actionBarStyle">@style/MyActionBarStyle</item>
</style>
将用箭头 activity 发射:
是否可以在使用AppCompatActivity
时指定getSupportActionBar().setDisplayHomeAsUpEnabled(true)
使用样式,而不是以编程方式这样做?
我可以指定可绘制对象本身,但如何使用样式启用它?
<style name="MyActivityTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarTheme">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="homeAsUpIndicator">@drawable/ic_clear</item>
<!-- Enable the above using a style attribute -->
</style>
无法通过 xml 启用它。您只能在清单中设置父项 activity:
<activity
android:name=".CurrentActivity"
android:label="@string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivityy" />
</activity>
但您无法通过 xml 启用它。不管怎样,它只是一行代码。
样式:
<style name="MyActionBarStyle" parent="Widget.AppCompat.Light.ActionBar.Solid">
<item name="displayOptions">showTitle|homeAsUp</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="actionBarStyle">@style/MyActionBarStyle</item>
</style>
将用箭头 activity 发射: