Android Studio开发之路(六)(合集)界面优化以及启动图标等

一、导航栏背景、字体修改

导航栏、状态栏等背景颜色的修改一般是在themes.xml文件中修改,android一个activity各个部件参考:
colorPrimary,colorPrimaryDark等的意义
添加链接描述

但是问题在于:只在这里修改背景颜色的话,可能会出现背景色和字体颜色重合导致看不清字,所以最好是背景色和字体色一起改,参考:
导航栏设置颜色字体

二、标题栏

(1)android提供的标题栏

android 提供的原装标题栏(ActionBar)可以通过以下步骤打开,并添加返回按钮

1、在themes.xml文件中有.NoActionBar, 将它删掉,状态栏就会出现了

2.修改标题

AndroidManifest.xml 文件的 < activity>中 增加 android:lable="标题文字"

  1. 在onCreate()函数中添加下面的代码,用于识别标题栏并添加返回按钮
cpp 复制代码
 //标题栏
        ActionBar actionBar = getSupportActionBar();
        if(actionBar!=null){
            Toast.makeText(this,"not null!1",Toast.LENGTH_SHORT).show();
            // actionBar.hide();   //隐藏标题栏
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);  //添加返回的图标
        }
  1. 添加返回响应函数
cpp 复制代码
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home :
                Intent intent = new Intent(NewsActivity.this,MainActivity.class);
                startActivity(intent);
                finish();
                break;

            default:
                break;
        }

        return super.onOptionsItemSelected(item);

    }

(2)自定义标题栏

android提供的ActionBar文字偏左,想要居中,于是自定义一个标题栏。参考:
自定义标题栏

三、activity之间的跳转

1. 通过Intent实现跳转,可加参数

cpp 复制代码
 Intent intent=new Intent(MainActivity.this,VerifyWatermark.class);
     //   String timename=timeStamp+".jpg";
    //    intent.putExtra("filename",fileName);
    //    intent.putExtra("Timename",timename);
        startActivity(intent);
        finish();

2. finish()

使用fininsh(),当activity跳转,当前activity就会结束。
finish的使用

四、drawable与图片尺寸

安卓手机型号繁多,为了适配多种机型,同一个图片需要不同的尺寸,于是在drawable中定义不同尺寸的文件夹,存放对应的图片,系统就会自动寻找适合的尺寸。

参考:
创建不同尺寸文件夹

五、启动图标和app名

1. 设置的位置

android:icon 和android:label分别设置图标和名字

2. 图标

图标同样需要不同的尺寸和形状以满足需要,android studio提供一个 image asset图标生成器帮助制作图标,制作好的图标自动存放到maimap路径下。

参考:
图标生成器的使用
制作自定义图标

相关推荐
booboosui4 小时前
编号没变,消息还是来了:Mac 端通知读取漏第二条的原因
android
雨白19 小时前
单例设计模式:从 Java/Kotlin 实现到 Android 实战
android
hai_android1 天前
一行 asLiveData,背后是一座生命周期的桥
android·java·kotlin
阿杰m1 天前
Android源码第二十三章:Telephony、RIL 与 IMS——来电怎么到应用?
android
booboosui1 天前
没人认领 .md:安卓把报告交给了音乐播放器打开
android
宝桥南山1 天前
Visual Studio 2026新特性 - 可以直接连接DeepSeek(使用Custom Endpoint Provider配置项)
ide·microsoft·微软·aigc·.net·visual studio
用户60709759149061 天前
AOSP 14 OTA 升级指导(四):update_engine 内部机制——Action 流水线与写盘
android
恋猫de小郭1 天前
Jetpack Compose 1.13 发布,憋了这么久终有交代了
android·前端·flutter
JMchen1231 天前
【Android 性能优化实战 60 讲】12 异步 Inflate 实战与痛击:源码拆解原生瓶颈,手写增强版布局预加载框架
android·性能优化·实战·启动优化·异步inflate·x2c
好的佩奇2 天前
蓝牙之设备角色与连接
android·flutter·蓝牙