bg_repeat.xml:
<?xml version="1.0" encoding="UTF-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/bg_pattern"
android:tileMode="repeat" />
bg_pattern.jpg:
if i launch app in portrait mode:
and output is okey.
and if launch app in landscape mode,sometimes output(in splashScreen BG and Main BG) is like:
and second problem in this mode(LandS): i change orientation to portrait,and press back button to close app,its refresh current activity(1,2,or even 4 time via each pressing Back btn)(refresh means go back to current activity from current! )
whats wrong? is this a bug?(each two question).
bytheway its my splashScreen.java code:
public class SplashScreen extends Activity {
private int _splashTime = 2000;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
new Handler().postDelayed(new Thread(){
#Override
public void run(){
Intent mainMenu = new Intent(SplashScreen.this, NextAct.class);
SplashScreen.this.startActivity(mainMenu);
SplashScreen.this.finish();
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
}, _splashTime);
}
}
after all i said,i use customTheme.
this is manifest xml code:
<activity android:theme="#style/CustomTheme"
android:label="#string/app_name"
android:name=".SplashScreen">
and this is part of styles.xml code:
<style name="CustomTheme" parent="#android:style/Theme.Light">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#drawable/bg_repeat</item>
</style>
but don't test this new app,that has problem or not.
Not repeating background is a known bug which was partially fixed in ICS and fully in JB. There's a workaround, you have to wrap bitmap in layout and then set repeating in code in onCreate like this :
parent = (RelativeLayout) findViewById(R.id.parent);
Bitmap bg = BitmapFactory.decodeResource(this.getResources(), R.drawable.bg_pattern);
BitmapDrawable patternRepeat = new BitmapDrawable(bg);
patternRepeat.setTileModeX(Shader.TileMode.REPEAT);
patternRepeat.setTileModeY(Shader.TileMode.REPEAT);
parent.setBackgroundDrawable(patternRepeat);
Related
I have an image which I want to place in splash screen in such a way that it is visible in navigation bar also at the top. Normally the image is visible in full activity except the navigation bar. But I want it to start from navigation bar also as in swiggy app splash screen.
Below is the related image:
Try this add to the manifest the theme of the first activity to exclude the action bar, and maybe even the notification bar?
Method 1
<application
android:allowBackup="true"
android:icon="#drawable/lojacidadao"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name="com.example.basicmaponline.Intro"
android:screenOrientation="portrait"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Method 2
Another way is, do this through code in the activity. In your activity do the following before calling setContentView() function
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
the reason you have the action bar is because you have set the default theme to have it, in the application tag, so it's not an activity before yours, it's really your own splash activity.
In your splash screen activity theme in styles.xml add
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
maybe if you set activity theme none(default in manifest) and set image fill_parent, the screen is displayed like that.
Try this:
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setFullScreenView();
}
public void setFullScreenView() {
if (Build.VERSION.SDK_INT < 19) {
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if (Build.VERSION.SDK_INT >= 19) {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
setContentView(R.layout.activity_splash); // set your view here
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
startActivity(MainActivity.class);
}
}, 2500);
}
/**
* #param cls ClassName.class to start new Activity
*/
private void startActivity(Class<?> cls) {
Intent intent = new Intent(SplashActivity.this, cls);
startActivity(intent);
finish();
}
#Override
public void onBackPressed() {
}
}
Question
How does one programatically (without touching the AndroidManifext.xml) set the theme of an Activity so that it looks like a dialog?
Note: I am ok with modifying the AndroidManifext.xml as long as it does not need to be modified in order to switch between making it look like a normal activity or a dialog.
What I've tried so far
I tried the following as per this stackoverflow answer:
public class DialogActivity extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
setTheme(android.R.style.Theme_DeviceDefault_Dialog);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dialog);
Log.d(TAG,"Build.VERSION.SDK_INT: "+Build.VERSION.SDK_INT); // 23
}
}
But it ends up blacking out everything in the background.
I also saw this stackoverflow answer, and tried:
public class DialogActivity extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
setTheme(android.R.style.Theme_DeviceDefault_Dialog);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dialog);
getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
}
}
but it ends up making everything black.
What do? Thank you.
Background
The Activity behind an Acivity is drawn if the foreground activity's theme according to its AndroidManifest.xml is a dialog; otherwise the android os will not draw the Activity behind it (probably to save memory since it usually won't be seen anyway).
To exploit this, we set the theme of our Acitvity to a dialog in the manifest, making the android os draw the Activity behind it, but later, programatically set our Activity's theme to whatever we like at runtime.
Example on github
I made an example and put it on github.
Tutorial
Step 1: create two custom themes for your application in styles.xml. One for normal activities, and another for dialog activities. It is important for the custom dialog theme to inherit from a base theme that is also a dialog. In my case, the parent theme is Base.Theme.AppCompat.Light.Dialog.FixedSize). Here is my styles.xml:
<resources>
<!-- custom normal activity theme -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
<!-- custom dialog activity theme -->
<style name="AppTheme.Dialog" parent="Base.Theme.AppCompat.Light.Dialog.FixedSize">
<!-- removing the dialog's action bar -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
</resources>
Step 2: in the AndroidManifest.xml, set the theme of the Activity in question to any dialog theme. This makes the android os think that the Activity is a dialog, so it will draw the Activity behind it, and not black it out. In my case, I used Theme.AppCompat.Dialog. Below is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.eric.questiondialog_artifact">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name">
<activity
android:name=".DialogActivity"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Dialog"> <-- IMPORTANT!!! -->
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Step 3: in the actual activity, set the theme programatically to either the theme for normal activities, or the theme for dialogs. My DialogActivity.java is below:
package com.example.eric.questiondialog_artifact;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
public class DialogActivity extends AppCompatActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
setTheme(R.style.AppTheme_Dialog); // can either use R.style.AppTheme_Dialog or R.style.AppTheme as deined in styles.xml
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dialog);
}
}
if what you're looking for is just a theme with transparent background for you activity, just use this:
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
apply this style to your activity in your AndroidManifest file and this is it
I am late but still for future users
you need to call the below code after setTheme() Calling this allows the Activity behind this one to be seen again. Once all such Activities have been redrawn
// setTheme()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try {
Method getActivityOptions = Activity.class.getDeclaredMethod("getActivityOptions");
getActivityOptions.setAccessible(true);
Object options = getActivityOptions.invoke(activity);
Class<?>[] classes = Activity.class.getDeclaredClasses();
Class<?> translucentConversionListenerClazz = null;
for (Class clazz : classes) {
if (clazz.getSimpleName().contains("TranslucentConversionListener")) {
translucentConversionListenerClazz = clazz;
}
}
Method convertToTranslucent = Activity.class.getDeclaredMethod("convertToTranslucent",
translucentConversionListenerClazz, ActivityOptions.class);
convertToTranslucent.setAccessible(true);
convertToTranslucent.invoke(activity, null, options);
} catch (Throwable t) {
}
} else {
try {
Class<?>[] classes = Activity.class.getDeclaredClasses();
Class<?> translucentConversionListenerClazz = null;
for (Class clazz : classes) {
if (clazz.getSimpleName().contains("TranslucentConversionListener")) {
translucentConversionListenerClazz = clazz;
}
}
Method method = Activity.class.getDeclaredMethod("convertToTranslucent",
translucentConversionListenerClazz);
method.setAccessible(true);
method.invoke(activity, new Object[] {
null
});
} catch (Throwable t) {
}
}
Try these code before dailog.setMessage(...);
Dialog id = new AlertDialog.Builder(this,AlertDialog.THEME_DEVICE_DEFAULT_DARK);
Dialog ID = new AlertDialog.Builder(this,AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
//Default theme
Try this for Old theme
Dialog ID = new AlertDialog.Builder(this,AlertDialog.THEME_TRADITIONAL);
Try these for KITKAT theme
Dialog ID = new AlertDialog.Builder(this,AlertDialog.THEME_DEVICE_DEFAULT_DARK); //Dark
Dialog ID = new AlertDialog.Builder(this,AlertDialog.THEME_HOLO_LIGHT);
Try these codes for Pragmatically
Exmaple
dialog = new AlertDialog.Builder(this);
dialog = new AlertDialog.Builder(this,AlertDialog.THEME_DEVICE_DEFAULT_DARK);
dialog.setTitle("HAI");
dialog.setMessage("look");
dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
Toast toast= Toast.makeText(getApplicationContext(), "This is exmaple theme", Toast.LENGTH_LONG);
I am trying to change the color of the background in my android app. At the moment when I press the button it changes the color for that specific activity and not for all the other activities. Is there a way to change it for the whole app?
public class colorPicker extends AppCompatActivity {
View view;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_color_picker);
view = this.getWindow().getDecorView();
}
public void goPink(View v){
view.setBackgroundResource(R.color.Pink);
}
public void goGreen(View v){
view.setBackgroundResource(R.color.Green);
}
public void goYellow(View v){
view.setBackgroundResource(R.color.Yellow);
}
}
create a theme in your styles.xml and add following to that theme
<item name="android:windowBackground">#color/window_background
and set android:theme="#style/YourTheme" in your
<application>
...
</application
in manifest file
In this case, You need to add few changes in your activity.
In on onCreate
if(getIntent().getExtras() != null)
{
int theme = getIntent().getIntExtra("theme", R.style.AppTheme);
setTheme(theme);
getApplication().setTheme(theme);
//recreate();
}
Condition onCLick
if(condition)
getIntent().putExtra("theme", R.style.AppTheme2);
else
getIntent().putExtra("theme", R.style.AppTheme);
and maintain 2 theme
<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary"></item></style>
and the second theme similar to it just change the name as BaseTheme2.
But this is not suggested to change the app theme at runtime.
You could change the window background color of your app theme and don't use a background for activities or you can use a transparent background for activities.
When you start android app Main activity starts with white background and black header with your app name in left corner. Like this
How to wholly remove this (when app is started not to show this) and add custom loading progress bar or some logo to the screen?
How about creating a splash dialog with custom layout containing progress bar?
In your main activity do something like this
private SplashDialog mSplashDialog;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
showSplashScreen();
setContentView(R.layout.yourmainlayout);
}
protected void removeSplashScreen() {
if (mSplashDialog != null) {
mSplashDialog.dismiss();
mSplashDialog = null;
}
}
protected void showSplashScreen() {
mSplashDialog = new SplashDialog(this, R.style.splash_dialog);
mSplashDialog.setCancelable(false);
mSplashDialog.show();
}
Create custom dialog
public class SplashDialog extends Dialog {
private ProgressBar mProgressBar;
public SplashDialog(Context context, int theme) {
super(context, theme);
setContentView(R.layout.splash_dialog);
mProgressBar = (ProgressBar) findViewById(R.id.splash_progress);
}
public void setProgress(int progress) {
mProgressBar.setProgress(progress);
}
}
And add style to that will let dialog fill all screen.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="splash_dialog">
<item name="android:padding">0dp</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowFrame">#null</item>
</style>
</resources>
To change dialog's progress value call mSplashDialog.setProgress(int progress).
When your data is loaded call removeSplashScreen().
I think what you're looking for can be found here:
how to change the splash screen
What worked for me (since I don't have much load up on start actually I didn't need splash screen at all) is changing res/values/styles.xml :
<resources>
<color name="custom_theme_color">#000000</color>
<style name="AppTheme" parent="android:Theme.Light" >
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#color/custom_theme_color</item>
</style>
</resources>
It just start with black screen witch goes to full screen (after 1-2 sec) when it is all loaded.
It looks very "profesional".
So I know you can use your own animation between activities using the overidePendingTransition method. I set up a transition between two activites and it works perfect on my emulator but I see no transition when I flash the app on to my phone. How can this be?
My emulator is running 2.2 as is my phone
Here is my onCreate method
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button = (Button) findViewById(R.id.close);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(ActivityTransitionActivity.this, ActivityTwo.class);
ActivityTransitionActivity.this.startActivity(myIntent);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
});
}
In your style.xml define your animation
<style name="Animation.CustomAnimation">
<item name="android:activityOpenEnterAnimation">#anim/slide_in_left</item> When opening a new activity, this is the animation that is run on the next activity
<item name="android:activityOpenExitAnimation">#anim/slide_out_right</item>When opening a new activity, this is the animation that is run on the previous activity (which is exiting the screen)
<item name="android:activityCloseEnterAnimation">#anim/slide_in_right</item>When closing the current activity, this is the animation that is run on the next activity (which is entering the screen).
<item name="android:activityCloseExitAnimation">#anim/slide_out_left</item>When closing the current activity, this is the animation that is run on the current activity (which is exiting the screen).
</style>
<style parent="android:style/Theme.Light.NoTitleBar.Fullscreen" name="app_theme">
<item name="android:windowBackground">#drawable/splash</item>
<item name="android:windowAnimationStyle">#style/Animation.CustomAnimation</item>
</style>
<application android:icon="#drawable/icon" android:label="#string/app_name"
android:theme="#style/app_theme">
apply app_theme to your application in android manifest
I had the same problem (on a samsung galaxy s). I found my answer at Activity animation not working in Galaxy Tab
Turns out animations are turned off by default on samsung devices. (It's a setting: Go to Settings -> display -> animations and then turn on the All animations and you will be able to see the animations)
Try this,
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(v.getContext(),
ActivityTwo.class);
startActivityForResult(myIntent, 0);
overridePendingTransition(R.anim.zoomextra, 0);
finish();
}
});