Practical tips of Android Studio APP

APP practical tips

This article introduces three tips for using app: (1) app start animation (2) hide app title bar (3) hide system notification status bar.

Article catalog

APP launch animation

Wechat and QQ have been integrated into our life. Careful little friends will find that each time they start these apps, there will be an opening animation.

Today, let's learn how to do this:
First, we need to create a new openActivity to load our startup code
We now complete the layout in the layout file:
Relative layout is adopted

<TextView
    android:id="@+id/texx"
    android:text="Launch interface"
    android:textSize="80sp"
    android:textColor="#EF4000"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

Let's start with simple text
Then, we set the logic in the java file:

welcomeImg = (TextView) this.findViewById(R.id.texx);
AlphaAnimation animation = new AlphaAnimation(0.5f, 1.0f);//Transition percentage
animation.setDuration(3000);//Display time
welcomeImg.startAnimation(animation);
animation.setAnimationListener(new AnimationImp1());}
private class AnimationImp1 implements Animation.AnimationListener {
    @Override
    public void onAnimationStart(Animation animation) {
    }

After the animation is started, it needs to be configured. After the animation is finished, jump:

@Override
        public void onAnimationEnd(Animation animation) {
            startActivity(new Intent(openActivity.this, MainActivity.class));
            finish(); //End jump
        }
        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    }
}

In this way, the configuration of our startup animation is basically completed. But a crucial step is missing:
We need to enter: AndroidMainfest.xml Configure startup files

<activity android:name=".openActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />   //Start item
    </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>!-->   //<! --- > is the annotation representation of the configuration file
</activity>

Change the original startup item mainactivity to oppenActivity

Let's look at the effect:

Text start animation, we are finished, but the use of text, a bit of prime. So how can we change it to image startup?
First, add an Imageview to the layout file

<ImageView
    android:id="@+id/open_img"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

Secondly, we need to put a picture in drawable. Here I found a picture directly from the Internet. The path is:
D:\Mytext "your Android folder" \ app\src\main\res\drawable
Then write the logic code in the java file. The content is roughly the same as our text startup, but some changes are needed:

 private ImageView welcomeImg= null;   //definition
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_open);   //This part is the original java code

        welcomeImg = (ImageView)this.findViewById(R.id.open_img); //Confirm picture
        AlphaAnimation animation = new AlphaAnimation(0.5f, 1.0f); //Over percentage
        animation.setDuration(3000);//Display time
        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(); //End jump
        }
        @Override
        public void onAnimationRepeat(Animation animation) {
        }
    }
}

Let's see how it works:

I keep the original text starter. If you don't want text, just delete it in the layout file
But through the comparison with wechat and QQ, we should find some differences.
The abrupt title block Mytext is very conspicuous and ugly.

Hide title block

How to remove the abrupt title block is the focus of this chapter. In fact, it only needs one line of code to complete:

getSupportActionBar().hide();//Hide title block

See how it works:

The moment is clear, and tall.
But the status bar of the system becomes the next blocker for aesthetics.

Hide system status bar

Only one line of code is needed to hide the system's status bar:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
//hide the status bar

This is the official calling code. There are many other official calling codes, such as calling the phone, calling the camera, calling the album, etc. interested students can learn about them.
Let's see how it works:

This is the effect of full screen animation.
Next time we'll discuss SQLite's approach, which is often referred to as database storage.
Remember to pay attention to me!!!!
Take you to explore Android development!!!

Tags: Android Java xml SQLite

Posted on Sat, 06 Jun 2020 01:56:42 -0700 by flappy_warbucks