super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bn=(Button)findViewById(R.id.clickme);
LayoutInflater inflater=MainActivity.this.getLayoutInflater();
View v= inflater.inflate(R.layout.alerdialog,null,false);
Context context=MainActivity.this;
AlertDialog.Builder builder=new AlertDialog.Builder(context);
//创建AlterDialog对象
builder.setView(v);
//输入文本
builder.setCancelable(false);
final AlertDialog alertDialog=builder.create();
//创建对象
bn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
alertDialog.show();
}
});
v.findViewById(R.id.cancle).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,“cancle”,Toast.LENGTH_LONG).show();
alertDialog.dismiss();
}
});
v.findViewById(R.id.signin).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,“Sign in”,Toast.LENGTH_LONG).show();
alertDialog.dismiss();
}
});
}
}
Activity.xml
<Button
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“点我”
android:id=“@+id/clickme”
android:layout_gravity=“center_horizontal” />
AlterDialog.xml
<LinearLayout
xmlns:android=“http://schemas.android.com/apk/res/android” android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:orientation=“vertical”>
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”>
<TextView
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:text=“AlertAialog”
android:textSize=“50dp”
android:textColor=“#fff”
android:gravity=“center”
android:background=“#334488”
android:paddingTop=“20dp”
android:paddingBottom=“20dp”/>
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:orientation=“vertical”
android:layout_marginTop=“10dp”>
<EditText
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:hint=“Username”
android:layout_marginLeft=“5dp”
android:layout_marginRight=“5dp”/>
<EditText
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:hint=“Password”
android:inputType=“textPassword”
android:layout_marginLeft=“5dp”
android:layout_marginRight=“5dp”/>
<LinearLayout
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:orientation=“horizontal”
android:layout_marginTop=“10dp”>
<Button
android:id=“@+id/cancle”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:background=“@drawable/shapdrawable”
android:gravity=“center”
android:text=“Cancel”
android:textColor=“#000” />
<Button
android:id=“@+id/signin”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:text=“Sign in”
android:background=“@drawable/shapdrawable”
android:textColor=“#000”
android:gravity=“center”
android:layout_weight=“1”/>
代码结果截图
2.3 XML menu
Android 提供了两种创建菜单的方式,一种是直接在java文件里写,另一种是在Android开发中使用较广的XML资源文件定义。笔者是使用不会使代码更臃肿的XML方法来定义。
<TextView
android:id=“@+id/textid”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“用于测试的内容!” />
public class MainActivity extends AppCompatActivity {
private final int size=110;
private final int common=111;
private final int color=112;
private TextView textId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textId=(TextView)findViewById(R.id.textid);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(1,size,1,“字体大小”);
menu.add(1,common,2,“普通菜单项”);
menu.add(1,color,3,“字体颜色”);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id=item.getItemId();
switch (id){
case size:
final AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle(“设置字体大小”);
builder.setSingleChoiceItems(new String[]{“10号字体”,“16号字体”,“20号字体”},-1,new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialogInterface, int i) {
switch (i){
case 0:textId.setTextSize(10);
dialogInterface.dismiss();
break;
case 1:textId.setTextSize(16);
dialogInterface.dismiss();
break;
case 2:textId.setTextSize(20);
dialogInterface.dismiss();
break;
}
}
});
builder.setNegativeButton(“取消”,null);
builder.show();
break;
case common:
Toast.makeText(this,“你点击了普通菜单项”, Toast.LENGTH_LONG).show();
break;
case color:
final AlertDialog.Builder builder2=new AlertDialog.Builder(this);
builder2.setTitle(“设置字体颜色”);
builder2.setSingleChoiceItems(new String[]{“红色”,“黑色”,“蓝色”},-1,new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialogInterface, int i) {
switch (i){
case 0:textId.setTextColor(Color.RED);
dialogInterface.dismiss();
break;
case 1:textId.setTextColor(Color.BLACK);
dialogInterface.dismiss();
break;
case 2:textId.setTextColor(Color.BLUE);
dialogInterface.dismiss();
break;
}
}
});
builder2.setNegativeButton(“取消”,null);
builder2.show();
break;
}
return super.onOptionsItemSelected(item);
}
}
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
![](https://i-blog.csdnimg.cn/blog_migrate/ab175e90ee1f180a6aa0790a593f0efd.jpeg)
写在最后
今天关于面试的分享就到这里,还是那句话,有些东西你不仅要懂,而且要能够很好地表达出来,能够让面试官认可你的理解,例如Handler机制,这个是面试必问之题。有些晦涩的点,或许它只活在面试当中,实际工作当中你压根不会用到它,但是你要知道它是什么东西。
最后在这里小编分享一份自己收录整理上述技术体系图相关的几十套腾讯、头条、阿里、美团等公司的面试题,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。
还有 高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料 帮助大家学习提升进阶,也节省大家在网上搜索资料的时间来学习,也可以分享给身边好友一起学习。
【Android核心高级技术PDF文档,BAT大厂面试真题解析】
【算法合集】
【延伸Android必备知识点】
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门即可获取!
,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。
还有 高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料 帮助大家学习提升进阶,也节省大家在网上搜索资料的时间来学习,也可以分享给身边好友一起学习。
【Android核心高级技术PDF文档,BAT大厂面试真题解析】
[外链图片转存中…(img-Jf23nNAN-1712023787677)]
【算法合集】
[外链图片转存中…(img-bVcplrDY-1712023787677)]
【延伸Android必备知识点】
[外链图片转存中…(img-PLaHx7Ze-1712023787677)]