android - 如何用 TextView 替换 Action Bar 应用标题?

标签 android android-studio

我已经使用

从我的操作栏中删除了应用标题
getSupportActionBar().setDisplayShowTitleEnabled(false);

在我的 onCreate 中。

我需要两件事的帮助:

  1. 如何通过 XML 删除应用标题,这样我的预览就不会再显示了?

  2. 我如何在我的操作栏中放置一个 EditText(我的是 R.id.urlField)来代替应用程序标题,互联网浏览器的 URL 字段应该在哪里?

示例代码和示例将不胜感激。

谢谢!

最佳答案

您可以像这样为 ActionBar 设置自定义 View :

getActionBar().setCustomView(R.layout.custom_actionbar);

然后您可以像这样从 ActionBar 中的自定义 View 中找到 View :

View actionBarView = getActionBar().getCustomView(); 

EditText editText = (EditText) acitonBarView.findViewById(R.id.editText);

或者你可以像这样直接将一个 View 实例设置为自定义 View :

 EditText editText = new EditText(context);
 getActionBar().setCustomView(editText);

再看看 --> Here

关于android - 如何用 TextView 替换 Action Bar 应用标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32030989/

相关文章:

android - Android JobService 需要导出吗?

php - 如何获取要在 php curl 请求的授权 header 中解析的 FCM 服务器 key ?

java - 在 ListAdapter 中使用 ImageView 时出现 OutOfMemoryError?

android - 如何使用 cmake 将 C 库转换为不同的 ABI

android - 以编程方式设置 Spinner VISIBLE 并启用

android - 从 Activity 返回到 fragment

Google Play 上的所有设备均不支持 Android 应用程序?

android - 任务 ':app:checkDebugAarMetadata set targetSdkVersion 30 and compileSdkVersion 30 执行失败

java - 在 Android Studio 中设置了错误的 JDK 路径

Android Studio 将使用过的导入语句设为未使用?