一、在Xml布局中
<android.support.design.widget.CoordinatorLayout 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"
android:orientation="vertical"
tools:context="com.example.asus.androidfire.WebActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:id="@+id/appBar"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_height="206dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:fitsSystemWindows="true"
app:title="AndroidFire"
app:contentScrim="#FFEDAA3d"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:layout_width="match_parent"
android:layout_height="206dp">
<ImageView
android:id="@+id/mShouYe_ItemClick_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFEDAA3d"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/logo"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingTop="24dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp">
<TextView
android:id="@+id/mShouYeItemWangZhang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android Fire 介绍:" />
<TextView
android:id="@+id/mShouYe_ItemClick_ShiJiang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text" />
</LinearLayout>
<WebView
android:id="@+id/mShouYe_ItemClick_WebView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/mShouYe_ItemClick_Floating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_share"
app:backgroundTint="#ed5b93"
app:elevation="10dp"
app:fabSize="mini"
app:layout_anchor="@+id/nestedScrollView"
app:layout_anchorGravity="right|top"
app:pressedTranslationZ="5dp"
app:rippleColor="#e7aa59" />
</android.support.design.widget.CoordinatorLayout>
二、在Activity中
public class WebActivity extends AppCompatActivity implements View.OnClickListener {
private ImageView mShouYe_ItemClick_image;
private Toolbar toolbar;
private CollapsingToolbarLayout collapsing_toolbar;
private AppBarLayout appBar;
private TextView mShouYeItemWangZhang;
private TextView mShouYe_ItemClick_ShiJiang;
private WebView mShouYe_ItemClick_WebView;
private NestedScrollView nestedScrollView;
private FloatingActionButton mShouYe_ItemClick_Floating;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
initView();
}
private void initView() {
mShouYe_ItemClick_image = (ImageView) findViewById(R.id.mShouYe_ItemClick_image);
mShouYe_ItemClick_image.setOnClickListener(this);
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setOnClickListener(this);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back);
setSupportActionBar(toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
collapsing_toolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
collapsing_toolbar.setOnClickListener(this);
appBar = (AppBarLayout) findViewById(R.id.appBar);
appBar.setOnClickListener(this);
mShouYeItemWangZhang = (TextView) findViewById(R.id.mShouYeItemWangZhang);
mShouYeItemWangZhang.setOnClickListener(this);
mShouYe_ItemClick_ShiJiang = (TextView) findViewById(R.id.mShouYe_ItemClick_ShiJiang);
mShouYe_ItemClick_ShiJiang.setOnClickListener(this);
mShouYe_ItemClick_WebView = (WebView) findViewById(R.id.mShouYe_ItemClick_WebView);
mShouYe_ItemClick_WebView.setOnClickListener(this);
nestedScrollView = (NestedScrollView) findViewById(R.id.nestedScrollView);
nestedScrollView.setOnClickListener(this);
mShouYe_ItemClick_Floating = (FloatingActionButton) findViewById(R.id.mShouYe_ItemClick_Floating);
mShouYe_ItemClick_Floating.setOnClickListener(this);
Intent intent = getIntent();
String tupian = intent.getStringExtra("tupian");
Glide.with(this).load(tupian).into(mShouYe_ItemClick_image);
final String web = intent.getStringExtra("web");
mShouYe_ItemClick_WebView.loadUrl(web);
mShouYe_ItemClick_WebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
mShouYe_ItemClick_WebView.loadUrl(web);
return true;
}
});
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.mShouYe_ItemClick_Floating:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
intent.putExtra(Intent.EXTRA_TEXT, "喜欢你傻傻的可爱");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent, "分享"));
break;
}
}
}