如何解决构建一个Andoid浏览器
我是android studio的新手。.我正在构建android网络浏览器,以我为乐。在这里,我对添加新的标签感到困惑。我使用片段作为标签。我在mainactivity布局上创建了一个按钮,当单击该按钮时,它将向片段容器中添加新片段。
类似的东西
public void add_tab()
{
id++;
int next_id = id+1;
String tag = String.valueOf(id);
Bundle bundle = new Bundle ();
bundle.putString ("tag",tag);
bundle.putInt ("id",id);
bundle.putInt ("next_id",next_id);
final FrameLayout tab_hosting_frame = new FrameLayout(getApplicationContext ());
FrameLayout.LayoutParams layoutparams_match_parent_match_parent = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT,Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);
tab_hosting_frame.setLayoutParams(layoutparams_match_parent_match_parent);
tab_hosting_frame.setBackgroundColor (Color.BLUE);
tab_hosting_frame.setId (id);
FragmentManager fragment_manager1 = getSupportFragmentManager ();
New_Tab new_tab_fragment = new New_Tab ();
FragmentTransaction fr_transaction = fragment_manager1.beginTransaction ();
fr_transaction.add ((tab_hosting_frame.getId ()),new_tab_fragment,tag);
fr_transaction.addToBackStack ("Fragment Add");
//new_tab_fragment.setArguments (bundle);
new_tab_fragment.setArguments (bundle);
fr_transaction.commit ();
tab_hosting_layout.addView (tab_hosting_frame);
//tab_hosting_layout.setVisibility (View.VISIBLE);
}
我也尝试过这种方式
public View create_tab()
{
id++;
String tag = String.valueOf(id);
linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View tab_view = new View (getApplicationContext ());
tab_view = linflater.inflate(R.layout.new_tab_view,null);
TextView show_id = (TextView)tab_view.findViewById (R.id.tab_id);
show_id.setText (tag);
tab_hosting_layout.addView (tab_view);
return tab_view;
}
然后执行,然后单击按钮,
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
tab_hosting_layout = (ConstraintLayout)findViewById (R.id.tab_host);
add_tab_button = (Button) findViewById (R.id.add_tab_button);
add_tab_button.setonClickListener (
new View.OnClickListener ()
{
@Override
public void onClick(View v)
{
add_tab ();
//or
//create_tab ();
}
}
);
在第二种方法中,情况是,当我单击后退按钮一次时,所有添加的选项卡(视图)都消失了一次。不是一步一步来。
这个方法好吗?还是有其他方法或方法可以像在普通的Web浏览器中一样创建无限的标签页?天气有点不对,我有点困惑。
如果你们知道可以帮助我解决任何问题...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。