我在一個項目中使用Android Sherlock,在其中顯示VideoView。屏幕方向爲人像時,會顯示視頻和一些文字。什麼時候是風景,只顯示全屏視頻。Action Bar Sherlock在從人像變爲風景時不保持透明度
嗯,我的疑問是:爲什麼當方向是縱向時會顯示(Sherlock Action Bar的)Alpha顏色,但是當方向是橫向時會改變它的alpha屬性(變成不透明)?
我的onCreate()如下顯示:
public void onCreate(Bundle savedInstanceState) {
// Makes action bar become translucent, and sets layout of this activity.
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
}
嗯,我使用requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY),這使得在操作欄中的Alpha顏色。
當方向改變時,我調用onConfigurationChanged(),它調用setScreenLayout()。此方法設置視頻大小並更改操作欄背景色。
/**
* Sets the screen layout, according with the current orientation.
*
* @param isInLandscapeMode
*/
public void setScreenLayout(Boolean isInLandscapeMode) {
// If orientation is landscape.
if (isInLandscapeMode) {
// Hides text of the layout.
mTextScrollView.setVisibility(View.GONE);
// Set the size of the video.
setVideoDimensions((int)Math.floor(mWindowWidth * (1/WIDESCREEN_RATIO)), mWindowWidth);
// Sets window to full screen.
setWindowToFullScreen();
// Sets action bar background color.
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.bg_translucent_black));
}
// If orientation is portrait.
else {
// Shows text of the layout.
mTextScrollView.setVisibility(View.VISIBLE);
// Set the size of the video.
setVideoDimensions(mWindowWidth, (int)Math.floor(mWindowWidth * WIDESCREEN_RATIO));
// Sets window to normal screen.
setWindowToNormalScreen();
// Sets action bar background color.
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.bg_translucent_black));
}
}
這個顏色設置在res/colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="bg_translucent_black">#11EEEEEE</color>
</resources>
在我AndroidManifest.xml中,我將與機器人的VideoActivity:configChanges = 「方向」屬性,它允許如果方向改變,則視頻繼續播放。
<!-- Video Activity -->
<activity
android:name=".VideoActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="orientation"
/>
因此,當方向改變時,onCreate()不會被調用。
我認爲正在發生的事情是,requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY)允許阿爾法只有當創建活動的第一方向(在這種情況下,縱向)。這樣,橫向方向不會變成字母顏色。但我不確定。
我敢肯定的是,我需要兩種方向的操作欄的alpha顏色。
任何人都知道,如果我的視頻可以在兩種方向上都有alpha顏色嗎?
那麼,我的視頻的兩個方向如何在我的Action Bar中有兩種不同的alpha顏色? – graffiti75
在您的Activity的onCreate中獲取設備的方向,並以這種方式動態設置ActionBar的Alpha顏色。 – SeanPONeil
我的視頻活動的默認方向必須是肖像。所以,我不會得到方向。視頻開始後(我可以完成翻轉的時候)我就會看到它。 問題在於alpha不起作用(並且在播放視頻時,我需要爲每個方向提供兩個不同的alpha值)。 只有在調用了onCreate()之後,alpha纔有效。但是在這個活動中,我在AndroidManifest中使用** android:configChanges =「orientation」**,這可以防止在方向更改時調用onCreate()。 – graffiti75