android – 在 *** 作栏的右上角添加一个按钮

android – 在 *** 作栏的右上角添加一个按钮,第1张

概述有没有办法可以在ActionBar的右上角添加一个按钮,就像默认设置按钮的位置一样?我删除了设置按钮,但我想在其中添加一个自定义按钮. 您可以通过编辑/创建菜单xml文件添加按钮: <?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android" x 有没有办法可以在Actionbar的右上角添加一个按钮,就像默认设置按钮的位置一样?我删除了设置按钮,但我想在其中添加一个自定义按钮.解决方法 您可以通过编辑/创建菜单xml文件添加按钮:
<?xml version="1.0" enCoding="utf-8"?><menu xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto">    <item        androID:ID="@+ID/action_name"        androID:icon="@drawable/you_resource_here"        androID:title="Text to be seen by user"        app:showAsAction="always"        androID:orderIncategory="0"/></menu>

然后在你的活动中,如果你创建了一个新的文件,你需要编辑onCreateOptionsMenu

@OverrIDepublic boolean onCreateOptionsMenu(Menu menu) {    // Inflate the menu; this adds items to the action bar if it is present.    getMenuInflater().inflate(R.menu.menu_main,menu);    return true;}

您可以编辑以下方法执行的 *** 作:

@OverrIDepublic boolean onoptionsItemSelected(MenuItem item) {    // Handle action bar item clicks here. The action bar will    // automatically handle clicks on the Home/Up button,so long    // as you specify a parent activity in AndroIDManifest.xml.    int ID = item.getItemID();    //noinspection SimplifiableIfStatement    if (ID == R.ID.action_name) {        return true;    }    return super.onoptionsItemSelected(item);}
总结

以上是内存溢出为你收集整理的android – 在 *** 作栏的右上角添加一个按钮全部内容,希望文章能够帮你解决android – 在 *** 作栏的右上角添加一个按钮所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1132605.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存