网页标题整改

This commit is contained in:
18401019693 2022-09-21 16:28:00 +08:00
parent 362dff002f
commit f8826d0239
6 changed files with 86 additions and 20 deletions

View File

@ -0,0 +1,12 @@
package com.yunbao.common.views.weight;
import android.app.Activity;
public class JavascriptInterface {
private Activity context;
public JavascriptInterface(Activity context) {
this.context = context;
}
}

View File

@ -0,0 +1,38 @@
package com.yunbao.common.views.weight;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.util.AttributeSet;
import android.webkit.WebView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
* pdlive对H5页面开放的web控件
*/
public class PDLiveWebView extends WebView {
public PDLiveWebView(@NonNull Activity context) {
super(context);
init(context);
}
public PDLiveWebView(@NonNull Activity context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
public PDLiveWebView(@NonNull Activity context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
@SuppressLint({"JavascriptInterface", "SetJavaScriptEnabled"})
private void init(Activity context) {
getSettings().setJavaScriptEnabled(true); // 是否开启JS支持
getSettings().setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口
getSettings().setDomStorageEnabled(true);
this.addJavascriptInterface(new JavascriptInterface(context), "androidObject");
}
}

View File

@ -1381,7 +1381,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
public void openLuckGiftTip() { public void openLuckGiftTip() {
UserBean u = CommonAppConfig.getInstance().getUserBean(); UserBean u = CommonAppConfig.getInstance().getUserBean();
String url = CommonAppConfig.HOST + "/h5/Noble/index.html?nickname=" + u.getUserNiceName() + "&usernobId=" + u.getNoble_id() + "&token=" + CommonAppConfig.getInstance().getToken() + "&uid=" + CommonAppConfig.getInstance().getUid() + "&anchorUid=" + mLiveUid + "&anchorName=" + mAncherName; String url = CommonAppConfig.HOST + "/h5/Noble/index.html?nickname=" + u.getUserNiceName() + "&usernobId=" + u.getNoble_id() + "&token=" + CommonAppConfig.getInstance().getToken() + "&uid=" + CommonAppConfig.getInstance().getUid() + "&anchorUid=" + mLiveUid + "&anchorName=" + mAncherName;
startActivity(new Intent(this, ZhuangBanActivity.class).putExtra("url", url)); startActivity(new Intent(this, ZhuangBanActivity.class).putExtra("url", url).putExtra("title", ""));
} }
/** /**

View File

@ -20,6 +20,7 @@ import android.webkit.WebViewClient;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
@ -59,6 +60,7 @@ public class ZhuangBanActivity extends AbsActivity {
private SVGAImageView svga; private SVGAImageView svga;
private FrameLayout title; private FrameLayout title;
private TextView titleView; private TextView titleView;
private RelativeLayout rootView;
@Override @Override
protected int getLayoutId() { protected int getLayoutId() {
@ -78,11 +80,21 @@ public class ZhuangBanActivity extends AbsActivity {
if (isFullWindow) { if (isFullWindow) {
title.setVisibility(View.GONE); title.setVisibility(View.GONE);
} }
if (getIntent().hasExtra("title") && TextUtils.isEmpty(titleString)) { if (getIntent().hasExtra("title")) {
title.setVisibility(View.GONE); if (TextUtils.isEmpty(titleString)){
} else { title.setVisibility(View.GONE);
title.setVisibility(View.VISIBLE); }else {
titleView.setText(titleString); if (TextUtils.equals(titleString, "blank")) {
title.setVisibility(View.GONE);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) rootView.getLayoutParams();
params.topMargin = DpUtil.dp2px(24);
rootView.setLayoutParams(params);
} else {
title.setVisibility(View.VISIBLE);
titleView.setText(titleString);
}
}
} }
mWebView = new WebView(mContext); mWebView = new WebView(mContext);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
@ -256,7 +268,6 @@ public class ZhuangBanActivity extends AbsActivity {
Log.i("tag", url); Log.i("tag", url);
Intent intent = new Intent(mContext, ZhuangBanActivity.class); Intent intent = new Intent(mContext, ZhuangBanActivity.class);
intent.putExtra("url", url); intent.putExtra("url", url);
intent.putExtra("isFull", false);
intent.putExtra("title", title); intent.putExtra("title", title);
mContext.startActivity(intent); mContext.startActivity(intent);
@ -369,7 +380,7 @@ public class ZhuangBanActivity extends AbsActivity {
Intent intent = new Intent(context, ZhuangBanActivity.class); Intent intent = new Intent(context, ZhuangBanActivity.class);
Log.i("tag", url); Log.i("tag", url);
intent.putExtra(Constants.URL, url); intent.putExtra(Constants.URL, url);
if (url.contains("Noble/index.html")){ if (url.contains("Noble/index.html")) {
intent.putExtra("title", ""); intent.putExtra("title", "");
} }
context.startActivity(intent); context.startActivity(intent);

View File

@ -40,6 +40,7 @@
</FrameLayout> </FrameLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/root_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">

View File

@ -74,20 +74,24 @@ public class ZhuangBanActivity extends AbsActivity {
} }
v_spacing = (View) findViewById(R.id.v_spacing); v_spacing = (View) findViewById(R.id.v_spacing);
lt_title = (LinearLayout) findViewById(R.id.lt_title); lt_title = (LinearLayout) findViewById(R.id.lt_title);
if (getIntent().hasExtra("title") && TextUtils.isEmpty(titleString)) { LinearLayout rootView = (LinearLayout) findViewById(com.yunbao.live.R.id.rootView);
lt_title.setVisibility(View.GONE); if (getIntent().hasExtra("title")) {
} else { if (TextUtils.isEmpty(titleString)){
lt_title.setVisibility(View.VISIBLE); lt_title.setVisibility(View.GONE);
}else {
if (TextUtils.equals(titleString, "blank")) {
lt_title.setVisibility(View.GONE);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) rootView.getLayoutParams();
params.topMargin = DpUtil.dp2px(24);
rootView.setLayoutParams(params);
} else {
lt_title.setVisibility(View.VISIBLE);
}
}
} }
// if (Constants.isTitle) {
// lt_title.setVisibility(View.VISIBLE);
// v_spacing.setVisibility(View.GONE);
// } else {
// lt_title.setVisibility(View.GONE);
// v_spacing.setVisibility(View.VISIBLE);
// }
L.e("H5---5>" + url); L.e("H5---5>" + url);
LinearLayout rootView = (LinearLayout) findViewById(R.id.rootView);
mProgressBar = (ProgressBar) findViewById(R.id.progressbar); mProgressBar = (ProgressBar) findViewById(R.id.progressbar);
svga = (SVGAImageView) findViewById(R.id.svga); svga = (SVGAImageView) findViewById(R.id.svga);
mWebView = new WebView(mContext); mWebView = new WebView(mContext);