【发布时间】:2018-10-18 12:11:42
【问题描述】:
好吧,当我显示一条信息时,我在选项卡中有一个 web 视图。问题是当我更改片段(我正在使用它)并返回时,webview 是空白的(黑色)。
我正在使用loadDataWithBaseURL 方法,我尝试填充historyUrl 参数,但得到相同的结果。
这是我的一段代码:
String html ="<html><head>" +
"<style type=\"text/css\">"+
"@font-face { font-family: '"+ AppData.getFont(context)+"'; src: url('"+AppData.getFont(context)+"'); }"+
"* {font-family: '"+AppData.getFont(context)+"'; font-size: "+font+" !important; font-weight:normal !important;}"+
"h1 {font-size: "+h1+" !important;}"+
"strong, b {font-family: '"+AppData.getFont(context)+"'; font-weight: bold !important;}"+
"</style>"+
"</head><body>",
ending="</body></html>";
Log.e("HTML", html);
String filename = "file:///android_asset/";
String myHtmlString = html + product.getCurrentDescription(context) + ending;
tvDescription.loadDataWithBaseURL(filename, myHtmlString, "text/html; charset=utf-8", "utf-8", filename);
这是我用来管理标签的方法:
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
TextView tvTabDescription = (TextView) inflater.inflate(R.layout.custom_tab_text,null);
TextView tvTabCondition = (TextView) inflater.inflate(R.layout.custom_tab_text,null);
TextView tvTabLocation = (TextView) inflater.inflate(R.layout.custom_tab_text,null);
//Creating custom tabs
tvTabDescription.setText(context.getResources().getString(R.string.tab_description));
tabLayout.addTab(tabLayout.newTab().setCustomView(tvTabDescription));
tvTabCondition.setText(context.getResources().getString(R.string.tab_conditions));
tabLayout.addTab(tabLayout.newTab().setCustomView(tvTabCondition));
tvTabLocation.setText(context.getResources().getString(R.string.tab_location));
tabLayout.addTab(tabLayout.newTab().setCustomView(tvTabLocation));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
final PagerAdapter pagerAdapter = new com.iurban.iurbanapp.Adapters.PagerAdapter(getFragmentManager(),tabLayout.getTabCount(), product, context);
viewPager.setAdapter(pagerAdapter);
viewPager.setOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
if(tab.getPosition() == 2)
ivProduct.setVisibility(View.GONE);
else
ivProduct.setVisibility(View.VISIBLE);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
我要分享这两张图片,第一张是第一次到达这个部分,第二张是点击“预约”按钮后返回。
当我点击“Reservar”按钮时,它会加载 FormFragment 片段:
formFragment = new FormFragment();
fragmentManager.beginTransaction()
.replace(R.id.fm_container, formFragment)
.addToBackStack(CustomConstants.FORM).commit();
然后返回执行调用super.onBackPressed()的onBackPressed()android方法;
我的 FormFragment 的 onCreate 看起来像下一段代码,这两种方法都只做“初始化组件(从 xml 获取视图)”和“为此组件初始化方法 onClick”:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_form, container, false);
initComponent(rootView);
initOnClicks();
return rootView;
}
提前谢谢你。
【问题讨论】:
-
您能否发布加载您的网络和活动的片段代码?
-
当然,我会编辑帖子显示标签的管理方法
-
请添加两张图片,一张是正常的,一张是异常的。我会重现您的问题并告诉您解决方案。
-
好的,我将编辑帖子并上传图片,其中一个在开始时作为选项卡工作,另一个在我转到下一个片段后按返回按钮时工作,谢谢你。
-
添加Reservar监听的代码sn-p,我想知道你是怎么回的,可能回的逻辑错误。
标签: android android-fragments webview tabs