Androidstudio修改theme隐藏顶部ActionBar 无响应?可能是这样…

Androidstudio修改theme隐藏顶部ActionBar 无响应?可能是这样…,第1张


安卓问题
    • 食用指南:
    • 框架/语言:
    • 问题描述:
    • 解决方案:
    • 安利时间:

食用指南:

框架使用过程中的问题首先要注意弃用方法的现有替代 & 引入内容本身是否有限制
当你在CSDN等网站查找不到最新版本框架的问题解决,别迟疑,马上去Goole
语言问题比框架问题稳定
如果本篇debug博客解决了你的问题,不妨留下你的👍
欢迎关注博主,查看更多c/c++/JAVA/算法/框架知识

框架/语言:
  • android studio 中的 xml配置文件
问题描述:
  • 当我们想要隐藏掉Android studio自带的顶部ActionBar

  • 查阅资料后发现只需要themes文件中style标签的parent选择为NoActionBar:

<resources xmlns:tools="http://schemas.android.com/tools">
    
    <style name="此处默认是你的项目名" parent="Theme.AppCompat.Light.NoActionBar">
        
        "colorPrimary">@color/purple_500
        "colorPrimaryVariant">@color/purple_700
        "colorOnPrimary">@color/white
        
        "colorSecondary">@color/teal_200
        "colorSecondaryVariant">@color/teal_700
        "colorOnSecondary">@color/black
        
        "android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant
        
    style>
resources>
  • 修改后重新运行发现APP端并没有去掉ActionBar
解决方案:
  • 需要将themes文件中style标签中的name重命名,不要采用默认的项目名称了
  1. 先修改style的name:
<resources xmlns:tools="http://schemas.android.com/tools">
    
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        
        "colorPrimary">@color/purple_500
        "colorPrimaryVariant">@color/purple_700
        "colorOnPrimary">@color/white
        
        "colorSecondary">@color/teal_200
        "colorSecondaryVariant">@color/teal_700
        "colorOnSecondary">@color/black
        
        "android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant
        
    style>
resources>
  1. 再修改清单文件maifest中android:theme = “@style/重命名的style名称”

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.finall">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/icon1"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:usesCleartextTraffic="true"
        android:theme="@style/AppTheme">
       
        
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            intent-filter>
        activity>
    application>

manifest>
安利时间:
  • 如果本篇博客解决了你的问题,不妨留下你的👍

    让博主知道原来也有小伙伴在同一个坑摔倒了啊hh

  • 欢迎关注大二的博主,在学习C/C++/JAVA/算法/框架的路上作伴

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

原文地址: https://outofmemory.cn/langs/919128.html

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

发表评论

登录后才能评论

评论列表(0条)

保存