这是一个带有工具栏,webView和浮动actionButton的布局(android 5.0中应该有一个浮动操作按钮):
我使用了CoordinatorLayout,因为其中有一个浮动操作按钮。如果将其更改为LinearLayout,则操作栏将可见,但FloatingActionButton不会浮动在屏幕上。将CoordinatorLayout更改为FrameLayout不会进行任何更改。怎么处理这个?
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_custom"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarStyle="outsideOverlay" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_favorite_white_24dp"
app:layout_behavior="com.drunkpiano.zhihuselection.utilities.ScrollingFavoriteFABBehavior" />
</android.support.design.widget.CoordinatorLayout>
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.drunkpiano.zhihuselection">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".activities.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.WebViewActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".activities.FavoritesActivity" />
<activity android:name=".activities.GuideActivity" />
<activity android:name=".activities.AnyActivity"></activity>
</application>
</manifest>
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!--<item name="android:listDivider">@drawable/shape_divider</item>-->
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="ListItemText" parent="android:Widget.Holo.Light.TextView">
<item name="android:gravity">center</item>
<item name="android:layout_margin">5dip</item>
<item name="android:minLines">3</item>
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="ThemeOverlay.YourApp" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="ActionBarTheme" parent="Theme.AppCompat.Light.DarkActionBar" >
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>