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
Related
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
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.
I need to set custom color both to actionbar and to client area. With the following code my app get succesfully colored, however, I still see the default theme for like 0.5 seconds when the activity starts. How do I remove this gap?
The color is set dynamically, so I guess I cannot use theme definition here. (I will later change my code to get color from an Intent)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note_screen);
setNoteColor(0xFFFFF8DC);
}
public void setNoteColor(int color) {
getWindow().getDecorView().setBackground(new ColorDrawable(color));
assert getActionBar() != null;
getActionBar().setBackgroundDrawable(new ColorDrawable(color));
}
Funny thing I just read about that yesterday... =)
Here is a great post regarding you issue
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
I am trying to change r=the color of the back ground on app load. For this I have used something like this :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final View view= new View(getApplicationContext());
view.post(new Runnable() {
#Override
public void run() {
view.setBackgroundColor(Color.BLACK);
}
});
addListenerOnButton();
}
This does not work. See the emulator screen shot below :
As you can see the back ground color is still white . Any ideas on what i can do to rectify this ?
Simple. Try this way.
this.findViewById(android.R.id.content).setBackgroundColor(Color.BLACK);
For ex:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.findViewById(android.R.id.content).setBackgroundColor(Color.BLACK);
}
Here findViewById(android.R.id.content) will return ContentView of current activity. Then you can set background for this view.
I hope this will help you.
First of all, view.post() is not necessary, because onCreate() already runs in the UI thread. Secondly, you are creating a View and setting the background of it, but you never set the view to anywhere, it's just an Object that never gets drawn. There are 2 solutions:
either:
View view= new View(this);
view.setBackgroundColor(Color.BLACK);
setContentView(view);
or, probably better:
setContentView(R.layout.activity_main);
View view = findViewById(R.id.root_laout); // set the root_layout in the layout xml file
view.setBackgroundColor(Color.BLACK);
This should do the trick:
this.findViewById(android.R.id.content).setBackgroundColor(Color.BLACK);