android - 如何将应用程序的图标与第一个活动的图标分开?
问题描述
我在清单文件中有问题。我的应用程序和第一个活动都有一个图标。但是当我在我的设备上运行应用程序时,应用程序图标是我第一个活动的图标。这是我的清单文件
我对应用程序的标签和第一个活动有同样的问题。我通过在运行时使用function setTitle()
. 有没有办法对图标做同样的事情?
解决方案
看一下这个:
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="@+id/toolbar"
android:background="?attr/colorPrimaryDark"
android:minHeight="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<LinearLayout
android:id="@+id/back_menu_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textColor="@color/white"
android:textSize="@dimen/abc_text_size_title_material"
android:gravity="left"
/>
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
您可以以编程方式设置徽标:
Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (getSupportActionBar()!=null){ getSupportActionBar().setTitle("bla bla bla"); getSupportActionBar().setLogo(R.drawable.logo); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); }
推荐阅读
- node.js - 使用 TypeScript 组织 nodejs-express 项目代码的最佳方法是什么?
- java - 如何在 IntelliJ 插件框架中使用 ConfigurableUI 类?
- javascript - 在 Node.js 中实现通知队列
- c# - NUnit 无法加载 MSTestAdapter/MSTestFramework DLL 并且“找不到任何测试”
- javascript - 如何使用 jest 模拟第三方库
- sql-server - 计算日期 1 和 2 之间的 datediff()
- excel - 根据其他 2 列中的条件对列中的几行求和
- java - Gradle:如何检查项目中的重复类?
- python - 导入模块以相对于导入它的文件进行文件操作
- sql - 从另一个表中选择 MAX(OrderDate) 上的 UnitCost