现在工具栏有1个ActionMenuVIEw和1个TextVIEw:
app_bar_transaction.xml:
<androID.support.v7.Widget.Toolbar androID:ID="@+ID/toolbar_transaction" androID:layout_wIDth="match_parent" androID:layout_height="?attr/actionbarSize" androID:background="#F6F6F6" app:popuptheme="@style/Apptheme.PopupOverlay" > <androID.support.v7.Widget.ActionMenuVIEw androID:ID="@+ID/menu_transaction" androID:layout_wIDth="wrap_content" androID:layout_height="?attr/actionbarSize" androID:layout_gravity="left" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_gravity="center" androID:textcolor="#5E5E5E" androID:textStyle="bold" androID:textSize="13sp" androID:ID="@+ID/toolbar_Title" androID:gravity="center" /></androID.support.v7.Widget.Toolbar>
我想将工具栏的内容更改为:
如何以编程方式更改工具栏的内容?
解决方法 像这样在工具栏的侧面添加linearLayout<androID.support.v7.Widget.ToolbarandroID:ID="@+ID/toolbar_transaction"androID:layout_wIDth="match_parent"androID:layout_height="?attr/actionbarSize"androID:background="#F6F6F6"app:popuptheme="@style/Apptheme.PopupOverlay" > <linearLayout androID:ID=@+ID/toolbar_item_container androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="horizontal" /></androID.support.v7.Widget.Toolbar>
然后在Java文件中访问此类线性布局
Toolbar mToolbar = (Toolbar)findVIEwByID(R.ID.toolbar_transaction);linearLayout layoutToolbar = (linearLayout)mToolbar.findVIEwByID(R.ID.toolbar_item_container);
现在使用此layoutToolbar添加或删除任何视图
layoutToolbar.addVIEw(); and layoutToolbar.removeVIEw();总结
以上是内存溢出为你收集整理的android – 如何以编程方式更改工具栏内容?全部内容,希望文章能够帮你解决android – 如何以编程方式更改工具栏内容?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)