android: setRequestedOrientation SCREEN_ORIENTATION_LANDSCAPE. How to change background - android

I am having
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
So when i start the app, for a fraction of time it show white screen before and after rotating to landscape, and then the application starts.
How to change the color of the background shown before the activity starts

Related

Application is not responding while using animation on Imageview

I've a imageview and animating the image infinitely with YoYo. I need to start a new activity AnimalIntroducer when this imageview is clicked. I can start new activity AnimalIntroducer clicking this animated button. But when clicking the back button in AnimalIntroducer activity when I come back to my HomeActivity then this animation on imageview stops, and button click becomes unresponsive and shows application is not responding. Do I have to run the animation in background thread? If so how can I do this?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_activity);
hangingMonkeyImageView = findViewById(R.id.monkey_hanging_image_view);
YoYo.with(Techniques.Bounce)
.duration(1000)
.repeat(-1)
.playOn(hangingMonkeyImageView);
hangingMonkeyImageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(HomeActivity.this,AnimalIntroducer.class);
startActivity(intent);
}
});
}
I would suggest you to stop the animation on view when the user navigates to the second activity, and restart the animation in onResume() method of HomeActivity.
If you want to learn more about it please see Android Activity Lifecycle

Android full screen theme for ICS and above

What Android theme should be used if I want full screen activities with white backgrounds running on devices supporting API 14+?
try this in your oncreate
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}

Force Main-Layout to Inflate

I'll try another shot. Hopefully now i get the answere i totally Need.
Just imagine:
I have a widget which calls(after onClick) a blank activity with no hardcoded code, just a Relative Layout with some views.(Layout provided by XML-layout-file).
My Activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myLayout);
When i add a for-loop to the onCreate-Method which adds 50 Buttons(take no care about layoutparams, orientation and so on). Just 50 simply Buttons
Like:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myLayout);
for(int i = 0; i<50; i++) {
Button btn = new Button(this);
myLayout.add(btn);
}
I recognize that he only Shows the activity on the Screen until he finished to add all the Buttons.
My Question is: How can i prevent this!? How can i Show up the Activity with the Content from the XML-layout file and then(ONLY then) add one Button after another to the Layout.
Is this possible? If so, do i neew to redraw the whole activity and so on. Please give me advise to my issue.

Show white screen until layout is completely constructed

My problem is that I have complicated layout, and when my application starts, I see how every view is adding to layout. I see my custom window title bar construction too. I see empty custom window title, with gradient background on start, and then 1 - 2 sec later I see completed window title with my views.
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
Is there simple way to show white screen, until my activity and custom title bar will be completely constructed?
The main trouble is that I cant start application with no title, and then add custom window title.
Only solution I know is splash screen, but it is too complicated for just this small task.
Use an asynctask like this:
private class LoadingMyView extends AsyncTask<void, void, int> {
protected void onPreExecute ()
{
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
//show whiteView
}
protected int doInBackground() {
return 0;
}
protected void onPostExecute(int result) {
//Hide white View
}
}
Note: I didnt test the code but i think more or less is ok
AsyncTask

How to apply Theme.Wallpaper at runtime on android?

I use following code :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme_Wallpaper);
setContentView(R.layout.main);
}
But it does nothing!
How can I apply Theme.Wallpaper at runtime on android?
It works when you call the setTheme() method even before the call to the constructor of your parent class (i.e. before super.onCreate(...)).
The following works for me:
public void onCreate(Bundle savedInstanceState) {
setTheme(android.R.style.Theme_Wallpaper);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
However, it's not perfect: when launching the activity, the shown animation still belongs to the default theme -> a black screen fades in. After the animation finishes, the wallpaper theme is shown.
If you want to have a wallpaper-themed fade-in animation, you have to use the declaration in your AndroidManifest.xml

Categories

Resources