我有一個按鈕,通過點擊所有的屏幕應該變得更黑,除了這個按鈕。我試圖改變顏色,主題,但它並沒有給我我想要的東西。現在我有一個想法,通過半透明視圖覆蓋整個屏幕,它的工作原理,但只涵蓋工具欄下的區域。問題是我無法弄清楚它是如何修復的。我無法覆蓋工具欄,無法確定如何讓我的按鈕可見。 它應該是這樣的: 如何通過透明視圖覆蓋整個屏幕(alpha 80%),除了一些元素?
我敢肯定有一個簡單的方法來做到這一點,如果有人用它的工作,請解釋。
我正在嘗試這樣做:在activity_main.xml中,我加了查看並通過按鈕單擊使其可見。但它再次只覆蓋Tab標題下的區域。
<View
android:id="@+id/transparent_view"
android:visibility="gone"
android:alpha="20"
android:background="@color/darkGrey"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</View>
全面佈局代碼:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.MainActivity">
<View
android:id="@+id/transparent_view"
android:visibility="gone"
android:alpha="20"
android:background="@color/darkGrey"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</View>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_main"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="Your Wi-Fi is online">
<Button
android:id="@+id/btn_pause"
android:layout_width="90dp"
android:layout_height="36dp"
android:layout_margin="17dp"
android:layout_gravity="end"
android:background="@color/white"
android:text="@string/pause"
android:textColor="@color/midPurple"
android:textSize="14sp" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
style="@style/AppTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar_main"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tabs" />
</RelativeLayout>
更改背景顏色 – Anonymous
@Anonymous它不適用於ToolBar,我只在Tab標題下覆蓋此區域 – VolodymyrH
您是否使用自定義工具欄?並請提供完整的xml文件。 –