2024年Android最新Android自定义Dialog,Toast,Notification和PopupWindow,2024年最新华为高级java面试题

总结

其实客户端开发的知识点就那么多,面试问来问去还是那么点东西。所以面试没有其他的诀窍,只看你对这些知识点准备的充分程度。so,出去面试时先看看自己复习到了哪个阶段就好。

Android大厂面试真题全套解析

2017-2020字节跳动Android面试真题解析PDF
然而Android架构学习进阶是一条漫长而艰苦的道路,不能靠一时激情,更不是熬几天几夜就能学好的,必须养成平时努力学习的习惯。所以:贵在坚持!

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:id=“@+id/toast_ll_main”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background=“#30000000”

android:orientation=“vertical”

android:padding=“20dp” >

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:orientation=“horizontal” >

<ImageView

android:layout_width=“30dp”

android:layout_height=“30dp”

android:src=“@drawable/ic_launcher” />

<TextView

android:id=“@+id/toast_tv”

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:textColor=“#0000ff”

android:textSize=“25dp” />

<TextView

android:id=“@+id/toast_time”

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:textColor=“#0000ff”

android:textSize=“25dp” />

绑定监听器:

btn_toast = (Button) findViewById(R.id.btn_toast);

btn_notify = (Button) findViewById(R.id.btn_notify);

btn_toast.setOnClickListener(new onClickListenerImp());

btn_notify.setOnClickListener(new onClickListenerImp());

核心内容都在监听函数里了:

private class onClickListenerImp implements OnClickListener {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

if (v == btn_toast) {

LayoutInflater inflater = LayoutInflater.from(Main.this);

View myView = inflater.inflate(R.layout.mytoast,

(ViewGroup) findViewById(R.id.toast_ll_main));

TextView toast_tv = (TextView) myView

.findViewById(R.id.toast_tv);

TextView toast_time = (TextView) myView

.findViewById(R.id.toast_time);

SpannableString spannableString = new SpannableString(

“Hello,Android! -zhoumushui”);

spannableString.setSpan(new ForegroundColorSpan(Color.YELLOW),

0, 14, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

spannableString.setSpan(new ForegroundColorSpan(Color.CYAN),

14, spannableString.length(),

Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

toast_tv.setText(spannableString);

// SimpleDateFormat sdf = new

// SimpleDateFormat(“yyyy-MM-dd HH:mm:ss:SSS”);

SimpleDateFormat sdf = new SimpleDateFormat(

“yyyy年MM月dd日 HH:mm:ss:SSS”);

toast_time.setText(sdf.format(new Date()));

Toast myToast = new Toast(Main.this);

myToast.setDuration(Toast.LENGTH_SHORT);

myToast.setView(myView);

myToast.setGravity(Gravity.CENTER, 0, 0);

myToast.show();

} else if (v == btn_notify) {

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

Notification notification = new Notification(

R.drawable.ic_launcher, “Hello,Android!–zhoumushui”,

System.currentTimeMillis());

notification.flags = Notification.FLAG_AUTO_CANCEL;

Intent intent = new Intent(Main.this, AfterClickNotify.class);

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP

| Intent.FLAG_ACTIVITY_NEW_TASK);

PendingIntent contentIntent = PendingIntent

.getActivity(Main.this, 0, intent,

PendingIntent.FLAG_UPDATE_CURRENT);

notification.setLatestEventInfo(Main.this, “Hello,Android!”,

“zhoumushui.”, contentIntent);

notificationManager.notify(R.string.app_name, notification);

}

}

}

有于只是演示,点击Notification后跳转到的Activity只是定义了布局,没做复杂处理:

public class AfterClickNotify extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.afterclicknotify);

}

}

布局:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical” >

<TextView

android:layout_width=“fill_parent”

android:layout_height=“fill_parent”

android:background=“#300000ff”

android:text=“Hello Android\nZhou Mu Shui\nblog.csdn.net/zhoumushui”

android:textSize=“25dp” />

好了,今天的内容比较基础,就先这样了,改日再写数据存储的内容。

代码工程下载

自定义PopupWindow:

效果图如下,类似iOS的ActionSheet:

核心代码:

package com.zms.actionsheet;

import android.app.Dialog;

import android.content.Context;

import android.content.DialogInterface.OnCancelListener;

import android.view.Gravity;

import android.view.LayoutInflater;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.Window;

import android.view.WindowManager;

import android.widget.LinearLayout;

import android.widget.TextView;

public class ActionSheet {

public interface OnActionSheetSelected {

void onClick(int whichButton);

}

private ActionSheet() {

}

public static Dialog showSheet(Context context, final OnActionSheetSelected actionSheetSelected,

OnCancelListener cancelListener) {

final Dialog dlg = new Dialog(context, R.style.ActionSheet);

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.actionsheet, null);

final int cFullFillWidth = 10000;

layout.setMinimumWidth(cFullFillWidth);

TextView mContent = (TextView) layout.findViewById(R.id.content);

TextView mCancel = (TextView) layout.findViewById(R.id.cancel);

mContent.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

actionSheetSelected.onClick(0);

dlg.dismiss();

}

});

mCancel.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

actionSheetSelected.onClick(1);

dlg.dismiss();

}

});

Window w = dlg.getWindow();

WindowManager.LayoutParams lp = w.getAttributes();

lp.x = 0;

final int cMakeBottom = -1000;

lp.y = cMakeBottom;

lp.gravity = Gravity.BOTTOM;

dlg.onWindowAttributesChanged(lp);

dlg.setCanceledOnTouchOutside(false);

if (cancelListener != null)

dlg.setOnCancelListener(cancelListener);

dlg.setContentView(layout);

dlg.show();

return dlg;

}

}

仿微信电话本短信标题的PopupWindow

刚刚看了部电影《Rush》,作为F1迷很是喜欢这种feel,让我想起了Ayrton Senna的那个年代,遗憾的是一味追求速度,难免会有悲剧伴随。

好了,步入正题。

在项目中我不是用PopupWindwow实现的,当时我的做法是利用布局的可见性,结合代码设置,虽然实现了同样效果,但是比较麻烦,并且不便于后期维护。

最近写了个小Demo,发现用PopupWindow实现方便很多,今天总结一下:

布局文件有两个:主文件布局main.xml和对应的popwindow.xml,布局都比较简单,也没有美化。主要逻辑都在代码里。

main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“fill_parent”

android:layout_height=“fill_parent”

android:background=“#ffffff”

android:orientation=“vertical” >

<LinearLayout

android:layout_width=“fill_parent”

android:layout_height=“50dp”

android:background=“#454545”

android:orientation=“horizontal”

android:weightSum=“5” >

<ImageButton

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_weight=“1”

android:background=“@null”

android:src=“@drawable/icon” />

<LinearLayout

android:layout_width=“wrap_content”

android:layout_height=“fill_parent”

android:layout_weight=“3”

android:onClick=“ShowOrHidePopup”

android:weightSum=“3” >

<TextView

android:id=“@+id/tv_topbar”

android:layout_width=“fill_parent”

android:layout_height=“fill_parent”

android:layout_weight=“1”

android:gravity=“center”

android:text=“短信”

android:textSize=“20dp” />

<ImageButton

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_weight=“1”

android:background=“@null”

android:src=“@drawable/icon” />

popwindow.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:background=“#454545”

android:orientation=“vertical” >

<View

android:layout_width=“fill_parent”

android:layout_height=“1px”

android:background=“#000000” />

<LinearLayout

android:layout_width=“fill_parent”

android:layout_height=“90dp”

android:orientation=“horizontal” >

<TextView

android:layout_width=“wrap_content”

android:layout_height=“90dp”

android:drawableTop=“@drawable/icon”

android:layout_weight=“1”

android:gravity=“center”

android:text=“收藏短信”

/>

<View

android:layout_width=“1px”

android:layout_height=“95dp”

android:layout_gravity=“center_vertical”

android:background=“#000000”

/>

<TextView

android:layout_width=“wrap_content”

android:layout_height=“90dp”

最后

文章不易,如果大家喜欢这篇文章,或者对你有帮助希望大家多多点赞转发关注哦。文章会持续更新的。绝对干货!!!

  • Android进阶学习全套手册
    关于实战,我想每一个做开发的都有话要说,对于小白而言,缺乏实战经验是通病,那么除了在实际工作过程当中,我们如何去更了解实战方面的内容呢?实际上,我们很有必要去看一些实战相关的电子书。目前,我手头上整理到的电子书还算比较全面,HTTP、自定义view、c++、MVP、Android源码设计模式、Android开发艺术探索、Java并发编程的艺术、Android基于Glide的二次封装、Android内存优化——常见内存泄露及优化方案、.Java编程思想 (第4版)等高级技术都囊括其中。

  • Android高级架构师进阶知识体系图
    关于视频这块,我也是自己搜集了一些,都按照Android学习路线做了一个分类。按照Android学习路线一共有八个模块,其中视频都有对应,就是为了帮助大家系统的学习。接下来看一下导图和对应系统视频吧!!!

  • Android对标阿里P7学习视频

  • BATJ大厂Android高频面试题
    这个题库内容是比较多的,除了一些流行的热门技术面试题,如Kotlin,数据库,Java虚拟机面试题,数组,Framework ,混合跨平台开发,等

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

程思想 (第4版)等高级技术都囊括其中。

[外链图片转存中…(img-PqmY6w3e-1715662573069)]

  • Android高级架构师进阶知识体系图
    关于视频这块,我也是自己搜集了一些,都按照Android学习路线做了一个分类。按照Android学习路线一共有八个模块,其中视频都有对应,就是为了帮助大家系统的学习。接下来看一下导图和对应系统视频吧!!!
    [外链图片转存中…(img-OUuXrQYi-1715662573069)]

  • Android对标阿里P7学习视频

[外链图片转存中…(img-hgS6chl4-1715662573069)]

  • BATJ大厂Android高频面试题
    这个题库内容是比较多的,除了一些流行的热门技术面试题,如Kotlin,数据库,Java虚拟机面试题,数组,Framework ,混合跨平台开发,等
    [外链图片转存中…(img-UPxNWF77-1715662573070)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 28
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值