有谁知道如何让活动背景透明并同时显示动作栏(不透明)?
我试过这个
<style name="Theme.PureTransparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
但是我收到了这个错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.activities.SearchTitleStrip}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4441)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.myapp.activities.SearchTitleStrip.setActionbarSearch(SearchTitleStrip.java:80)
at com.myapp.activities.SearchTitleStrip.onCreate(SearchTitleStrip.java:72)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4441)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke
SearchTitleStrip类中的第80行是这段代码:
actionBar.setDisplayShowTitleEnabled(false);
答案 0 :(得分:0)
你为什么不设置
android:background="#AARRGGBB"
活动xml中的,其中AA是alpha值(透明度级别),后面是红色绿色和蓝色。
答案 1 :(得分:0)
我已将问题添加到styles.xml中解决了我的问题(我使用了操作栏Sherlock):
<style name="AppTheme.ActionBarTransparentBackground" parent="@style/Widget.Sherlock.ActionBar">
<item name="background">@android:color/transparent</item>
<item name="android:background">@android:color/transparent</item>
</style>