java - 我应该在我的依赖项中添加什么来制作工具栏?
问题描述
我想删除操作栏并用工具栏替换,但我不知道要为我的依赖项添加什么!这是我的 gradle.build 文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.helloword"
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
解决方案
您可以将此主题添加到您的样式中:
<style name="MainTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/loginBackground</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
将此添加到 AndroidManifest.xml 中的活动主题
<activity android:name=".YourActivity"
android:theme="@style/MainTheme" />
现在您可以将工具栏添加到您的活动 xml 文件中
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
现在终于将它添加到您的活动中
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
推荐阅读
- javascript - 开玩笑,如何模拟一个模拟函数返回的函数
- java - Java - 使用布尔值转换为 Lambda 以返回
- slider - 我想在底部显示 slcik 滑块下一张图片作为箭头,但不想显示上一张幻灯片
- ios - 如何在 SwiftUI 中引用外部 iOS 系统状态更新?
- java - 如何在 Spring Boot 中发送带有 json 值的多部分表单数据
- javascript - 用过时的状态对 Render 中的传递道具做出反应
- android - 带有多个项目的 recycleView 上的 Android SearchView
- java - java spring注解报错,@OneToMany和@ManyToOne关系报错
- python-3.x - 如何将 Numpy 数组的元素分配给对象的指针(另一个 Numpy 数组)?
- youtube-api - youtube v3 API“相关性”排序顺序到底是什么意思?