nha*_*man 35 android actionbarsherlock
Google地图应用程序具有透明的ActionBar,通过该ActionBar可以看到地图.

我可以使用以下方法设置ActionBar的透明度:
<style name="Theme.MyTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/ActionBar</item>
</style>
<style name="ActionBar" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">#64000000</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但是如何在ActionBar后面显示我的ImageView?
Tom*_*mik 43
您可以启用叠加模式ActionBar.要做到这一点,你必须(android:)windowActionBarOverlay在主题中设置项目true.
<style name="MyTheme" parent="Theme.Sherlock">
...
<item name="windowActionBarOverlay">true</item> <!-- for ActionBarSherlock -->
<item name="android:windowActionBarOverlay">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
Sid*_*ele 26
您也可以在运行时设置它:
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
Run Code Online (Sandbox Code Playgroud)
这将是ActionBar的一个半透明浮动条.
像任何一样requestWindowFeature...,这应该在添加内容之前调用.
之后setContentView,您可以Drawable使用此设置背景:
getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg));
Run Code Online (Sandbox Code Playgroud)
更改getActionBar与getSupportActionBar用于ActionBarSherlock
actionbar_bg.xml与形状的根元素:
<solid android:color="#64000000" />
Run Code Online (Sandbox Code Playgroud)
虽然我发现Tomik的解决方案很棒,但对于那些一次性案例而言,这对于一些活动而不是全面的风格都很有用.
Mar*_*rre 10
如果某人需要透明栏但仅针对某些活动,而在其余部分中使用实体,则可能值得创建两种不同的样式并使用清单来控制它:
<style name="MyThemeOverlay" parent="Theme.Sherlock">
...
<item name="windowActionBarOverlay">true</item> <!-- for ActionBarSherlock -->
<item name="android:windowActionBarOverlay">true</item>
<!-- any stuff common here, colours, etc -->
<!-- define the style for native ActionBar for Android 4 and higher -->
<item name="android:actionBarStyle">@style/myActionbarTransparent</item>
<!-- define the style for ActionBarSherlock -->
<item name="actionBarStyle">@style/myActionbarTransparent</item>
</style>
<style name="MyThemeNoOverlay" parent="MyTheme">
<item name="windowActionBarOverlay">false</item> <!-- for ActionBarSherlock -->
<item name="android:windowActionBarOverlay">false</item>
<!-- any stuff specific for no overlay activity action bars -->
<!-- define the style for native ActionBar for Android 4 and higher -->
<item name="android:actionBarStyle">@style/myActionbar</item>
<!-- define the style for ActionBarSherlock -->
<item name="actionBarStyle">@style/myActionbar</item>
</style>
<style name="myActionbar" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">@color/white</item>
</style>
<style name="myActionbarTransparent" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">@color/transparent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然后在你的AndroidManifest.xml你可以使用其中一个作为默认值,另一个用于某些特定活动,例如:
<application
...
android:theme="@style/MyThemeOverlay">
...
<activity
android:name=".Activity1"
/>
<activity
android:name=".Activity2"
android:theme="@style/MyThemeNoOverlay"
/>
<activity
android:name=".Activity3"
/>
<activity
android:name=".Activity4"
android:theme="@style/MyThemeNoOverlay"
/>
Run Code Online (Sandbox Code Playgroud)
...
| 归档时间: |
|
| 查看次数: |
17859 次 |
| 最近记录: |