The content of the notes is the Android development tutorial for drinking (the latest version of 2019, using JetPack)
1. Set up a different locale
Added translations editor
, and then we can click directly open editor
, and then add the corresponding language in the graphical interface, first click the globe icon, then select the desired language, and finally add the corresponding meaning. Such as:
2. Screen rotation
Similarly, in the visual interface, you can set the corresponding layout file after the screen is rotated:
select,, and create landscape variation
then you can start writing the corresponding layout of the horizontal screen, such as:
Similarly, the corresponding layout file will be automatically loaded according to the system status .
2.1 Data saving of screen rotation
As the screen is rotated, the oncreate
method will be re-executed to perform layout
the rendering and loading of the layout file, so it is necessary to save some operations in the original vertical screen, and then load the original data in the horizontal screen.
It's very simple, only Bundle
the data in the storage is needed, and it can be rewritten specifically onSaveInstanceState
, such as:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(savedInstanceState!=null){
String key = savedInstanceState.getString("Key");
}
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState, @NonNull PersistableBundle outPersistentState) {
super.onSaveInstanceState(outState, outPersistentState);
outState.putString("KEY", "Value");
}
}