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路径下。

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

相关推荐
android_xc23 分钟前
Android Studio适配butterknife遇到的坑
android·ide·android studio·butterknife
2501_9159184137 分钟前
uni-app 项目 iOS 上架效率优化 从工具选择到流程改进的实战经验
android·ios·小程序·uni-app·cocoa·iphone·webview
云梦谭1 小时前
Cursor 编辑器:面向 AI 编程的新一代 IDE
ide·人工智能·编辑器
00后程序员张1 小时前
如何在不同 iOS 设备上测试和上架 uni-app 应用 实战全流程解析
android·ios·小程序·https·uni-app·iphone·webview
米豆同学3 小时前
SufraceFlinger图像合成原理(3)-SurfaceFlinger中Layer的创建和销毁
android
米豆同学3 小时前
SufraceFlinger图像合成原理(2)-SurfaceFlinger与应用进程间的通信
android
用户2018792831673 小时前
uses-library:系统应用报NoClassDefFoundError问题
android
叽哥3 小时前
Kotlin学习第 4 课:Kotlin 函数:从基础定义到高阶应用
android·java·kotlin
mg6683 小时前
安卓玩机工具----安卓“搞机工具箱”最新版 控制手机的玩机工具
android·智能手机
诺诺Okami3 小时前
Android Framework- Activity启动2
android