APP实用小技巧
本篇介绍三个App的使用小技巧,(1)App启动动画(2)隐藏APP标题栏(3)隐藏系统通知状态栏。
APP启动动画
微信、QQ已经融入我们的生活,细心的小伙伴会发现,每次启动这些APP的时候,都会有一个开场动画。


今天我们就来学习一下这是怎么做到的:
首先我们需要还需创建一个新的openActivity,用来装载我们的启动代码
我们现在布局文件中,完成布局:
采用的是相对布局——RelativeLayout
<TextView
android:id="@+id/texx"
android:text="启动界面"
android:textSize="80sp"
android:textColor="#EF4000"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
我们先尝试单纯的文字启动动画
而后,我们在java文件中进行,逻辑设定:
welcomeImg = (TextView) this.findViewById(R.id.texx);
AlphaAnimation animation = new AlphaAnimation(0.5f, 1.0f);//过渡百分比
animation.setDuration(3000);//显示时间
welcomeImg.startAnimation(animation);
animation.setAnimationListener(new AnimationImp1());}
private class AnimationImp1 implements Animation.AnimationListener {
@Override
public void onAnimationStart(Animation animation) {
}
动画的启动完成了,还需要配置,动画结束完成后进行跳转:
@Override
public void onAnimationEnd(Animation animation) {
startActivity(new Intent(openActivity.this, MainActivity.class));
finish(); //结束跳转
}
@Override
public void onAnimationRepeat(Animation animation) {
}
}
}
这样,我们的启动动画的配置大致完成了。但还缺少很关键的一步:
我们需要进入到:AndroidMainfest.xml配置启动文件
<activity android:name=".openActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> //启动项
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<!--<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>!--> //<!-- -->是配置文件的注释表达方法
</activity>
把原本的启动项MainAcitity改为oppenActivity
我们看一下效果:
文字启动动画,我们算是完成了,但使用文字的,有点素。那我们怎么改成图片启动呢?
首先在布局文件中先加入一个Imageview
<ImageView
android:id="@+id/open_img"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
其次我们需要在drawable放一张图片,这里我就直接从网上找到了一张图,路径为:
D:\Mytext “你的安卓文件夹”\app\src\main\res\drawable
随后在java文件进行逻辑代码编写,内容和我们文字启动大致相同,但也需要一些更改:
private ImageView welcomeImg= null; //定义
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_open); //这一部分是java原代码
welcomeImg = (ImageView)this.findViewById(R.id.open_img); //确定图片
AlphaAnimation animation = new AlphaAnimation(0.5f, 1.0f); //过度百分比
animation.setDuration(3000);//显示时间
welcomeImg.startAnimation(animation);
animation.setAnimationListener(new AnimationImp1());}
private class AnimationImp1 implements Animation.AnimationListener {
@Override
public void onAnimationStart(Animation animation) {
welcomeImg.setBackgroundResource(R.drawable.open);
}
@Override
public void onAnimationEnd(Animation animation) {
startActivity(new Intent(openActivity.this,MainActivity.class));
finish(); //结束跳转
}
@Override
public void onAnimationRepeat(Animation animation) {
}
}
}
让我们看看效果如何:
我保留了:原来的文字启动项。如果你不想要文字的话,仅仅只需要在布局文件中把删除即可
但通过和微信、QQ的对比,应该发现了一些不一样。
突兀的标题栏Mytext,非常的显眼且难看。
隐藏标题栏
如何去掉突兀的标题栏,是本章的重点。其实只需要一行代码就可完成:
getSupportActionBar().hide();//隐藏标题栏
看看效果如何:
瞬间明朗起来,且高大上。
但系统的状态栏成为了美观的下一个拦路虎。
隐藏系统状态栏
隐藏系统的状态栏也只需要一行代码:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
//隐藏状态栏
这是官方的调用代码,官方的调用代码还有很多:比如调用电话,调用相机,调用相册等,有兴趣的同学可以去了解一下。
让我们再看看效果如何:
这就是全屏启动动画的效果。
下一次我们讨论讨论SQLite的方法,也就是常说的数据库存储。
记得关注我!!!!
带你探索Android开发!!!