When I create an android app this is generated automatically:
How do I get rid of this? Its ugly
EDIT
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenWidth = size.x;
screenHeight = size.y;
you can try this :
requestWindowFeature(Window.FEATURE_NO_TITLE);
Note that this has to be called before setContentView(XYZ_xml)
There are other Window Features too, like no action bar and no title etc.
See the javadoc for more help
you can also add this to work with xml like this :
android:theme="#android:style/Theme.NoTitleBar
Try adding this to the <application> tag your manifest:
android:theme="#android:style/Theme.NoTitleBar"
In your activity, use before setContentView():
requestWindowFeature(Window.FEATURE_NO_TITLE);
try applying the theme to your activity in your manifest. You might have to change the theme depending on your support library:
android:theme="#android:style/Theme.NoTitleBar
Add Theme to you manifest like others have said. Avoid putting code in your java activity file instead because if you do that, when you run your application you will see the action bar for a very short duration (enough to notice it) before it goes away.
Related
I am trying to add an image into my app with java so I googled how to do this and seen I had to add
Context mContext;
Drawable myImage = mContext.getDrawable(R.drawable.my_image);
(That was all of the code they said I had to add) But when I run it I don't see my image I set to it. So how I would be able to show the image I set to it?
For a image to be displayed, you need to give a view for that . ie - ImageView
Add a ImageView in your main-layout.
Initialize that ImageView in the on create of your activity like
ImageView appImage = findViewById(R.id.your_image_View_id);
3.Then set an image to the image view like
appImage.setImageResource(R.drawable.your_image);
Hope this helps.
You just initialize the imageview from layout like below,
ImageView appImage = findViewById(R.id.your_image_View_id);
appImage.setImageDrawable(ContextCompat.getDrawable(getActivity(),R.drawable.ic_downarrow));
With new android API 22 getResources().getDrawable() is now deprecated. So now the best approach is to use only getDrawable() is using ContextCompat
Please follow the steps:
Step1: In your main_layout.xml, add an <ImageView ... tag give an id, let's say id is "imageView"
Step2: In your MainActivity.class onCreate() method, Initialize that ImageView as:
ImageView image = findViewById(R.id.imageView)
then,
Step3: assign your drawable as:
im.setImageDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.your_image_drawable));
If you are using a fragment, use:
im.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.your_image_drawable));
Hope it helps. Please update if it does.
ImageView appImage = findViewById(R.id.your_image_View_id);
In activity simply use setImageResource
appImage.setImageResource(R.drawable.ic_avatar);
I have an activity that has android:windowIsTranslucent set to true and android:windowBackground set to a translucent background. I just changed my target and compile sdk version to 27, and I get an exception when launching this activity now:
java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
Since this is a new sdk, there isn't anything online about it yet (and it seems to result from this line of code: https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/app/Activity.java#987 )
Is there any way to get around this? The app doesn't crash if I take out android:screenOrientation="portrait" from my manifest for this activity, but I would like to be able to keep it like that.
I also faced the same problem.
As others said, If I deleted android:screenOrientation="portrait" or overrided it with android:screenOrientation="unspecified", then the exception was gone.
And it seems that the front activity's orientation follows the behind activity's orientation.
I thought about it.
If the front activity is transparent and the behind activity's orientation is different,
the display becomes strange.
So, I can understand why this check logic was added
However, I wonder that why this problem was not occurred in Developer Preview 8.0.0.
The workaround is to set targetSdk back to 26.
The reason why is your application crashes is here in this commit.
As you can see here, you are not the only one - this behavior has been reported to Google as issue. It has been fixed, but we don't know how and when it will be released.
I can also confirm what "sofakingforever" says in comments, if there is non-translucent activity with fixed orientation behind your translucent, the translucent will not rotate. So you can just remove android:screenOrientation="portrait" from manifest as well.
The solution worked for me is deleting
android:screenOrientation="portrait"
from all the full screen transparent activities which means their theme contains
<item name="android:windowIsTranslucent">true</item>
Also to make sure that orientation works correct for below Oreo I added this to the onCreate() of the activities.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// This activity is a fullscreen transparent activity, so after Oreo Android doesn't allow fullscreen
// transparent activities to specify android:screenOrientation="portrait" in the manifest. It will pick up
// from the background activity. But for below Oreo we should make sure that requested orientation is portrait.
if (VERSION.SDK_INT < VERSION_CODES.O) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
I solved this issues by changing this line in NoActionBar styles
In target version 27 only i got this issue and i solved by using below line
<item name="android:windowIsTranslucent">false</item>
So what I did was remove any screenOrientation property from manifest and add it to my BaseActivity (from which all my activities extend), this code
if(!(this instanceof TranslucentActivity)){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
The TranslucentActivity will have the orientation from the Activity behind.
it seems like it's a new feature/bug on API 27.
However, you can delete
android:screenOrientation
Or
android:screenOrientation="unspecified"
I recently faced the issue and here's the solution.
No need to change the screen orientation parameter which you set at the android manifest file.
Just add two folders in
res>values
as res>values-v26
and res>values-v27
Then copy your styles.xml and themes.xml file there.
and change the following parameters from TRUE to FALSE.
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowIsTranslucent">false</item>
It will work.
A common bug of Android 8.0
Thanks #JerabekJakub. My test result - keep sdk 27 and remove the following lines can also solve the crash.
android:configChanges="orientation"
android:screenOrientation="portrait"
1) Remove this
android:screenOrientation="portrait"
from minifiest.xml
2) on Activity add these two lines
protected void onCreate(Bundle savedInstanceState) {
setOrientation(this)
super.onCreate(savedInstanceState);
// other other all code here
}
3) Just copy-paste the code in your Activity
public static void setOrientation(Activity context) {
if (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.O)
context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
else
context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
I had this problem on Android 8 using BottomSheetDialogs. It was crashing every time I open some translucent bottom sheet dialog.
I fixed the problem by adding new theme.xml in values-v26, with same theme as default one, but completely removing windowIsTranslucent item from there.
After that, I still had translucent bottom sheet dialogs in my app and it is working perfectly.
Found it interesting. It may help someone using these dialogs.
I'm developing an Android app that needs to support 2.3+. I'm using HoloEverywhere as a layout library. My app runs perfectly on smartphones and tablets, but for now I'm using the same layout for all devices, so, in tablets there is a lot of blank space in a lot of layouts. So, I thinking if is possible to show this layout as a popup (AlertDialog) just on large screens.
I searched the internet for a response but every response I look isn't applying to my case. I don't want to change my layouts files (and, of course, I don't want to create new layout files).
Can anyone give a direction to solve my problem, or the unique way is to create new layouts for large screens?
You can use your own layout file as the content view of a dialog. With a custom view you can create other/bigger dialogs for your tablets. It is also possible to create a dialog from an activity. See http://developer.android.com/guide/topics/ui/dialogs.html#ActivityAsDialog or http://developer.android.com/guide/topics/ui/dialogs.html#FullscreenDialog
You can change the theme of activity to dialog in Manifest file. See:
<activity
android:name="Activity"
android:label="Home"
android:theme="#android:style/Theme.Holo.Dialog">
</activity>
You can use this code to change the height and width of my activity in onCreate()..It provides better flexibility than specifying dialog theme
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
requestWindowFeature(Window.FEATURE_ACTION_BAR);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
android.view.WindowManager.LayoutParams params =
getWindow().getAttributes();
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
params.height = LayoutParams.WRAP_CONTENT;
params.width = (int) (width / 1.2); // fixed width
params.alpha = 1.0f;
params.dimAmount = 0.5f;
getWindow().setAttributes((android.view.WindowManager.LayoutParams)
params);
I want to make an activity that can be opened above ANY app.
Normally, even when the activity is set as dialog, when you switch to my app, you see my app, and in the background you see the launcher:
BUT, I want the app will go above any app like this: (made in photoshop):
I did see this question Creating a system overlay window (always on top), but in ICS there is no functionallity to the layout.
Furthermore, I want to give a dialog box from my app without minimizing the other app...
there are plenty of apps that show a floating view on top of everything like : airbrowser , LilyPad , Stick it , AirTerm , Smart Taskbar , aircalc ...
anyway , in order to achieve this feature , you must have a special permission called "android.permission.SYSTEM_ALERT_WINDOW" , and use something like that:
final WindowManager.LayoutParams param=new WindowManager.LayoutParams();
param.flags=WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
final View view=findViewById(R.id.my_floating_view);
final ViewGroup parent=(ViewGroup)view.getParent();
if(parent!=null)
parent.removeView(view);
param.format=PixelFormat.RGBA_8888;
param.type=WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
param.gravity=Gravity.TOP|Gravity.LEFT;
param.width=parent!=null?LayoutParams.WRAP_CONTENT:view.getLayoutParams().width;
param.height=parent!=null?LayoutParams.WRAP_CONTENT:view.getLayoutParams().height;
final WindowManager wmgr=(WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.addView(view,param);
// TODO handle overlapping title bar and/or action bar
// TODO you must add logic to remove the view
// TODO you must use a special permission to use this method :android.permission.SYSTEM_ALERT_WINDOW
// TODO if you wish to let the view stay when leaving the app, make sure you have a foreground service running.
I'm one of the developers of the Tooleap SDK, and we also dealt with this issue.
Basically, you don't need to use the SYSTEM_ALERT_WINDOW to display an activity on top of another one. You can just display a regular "shrinked" Activity with a transparent background.
To make a "shrinked Activity, change the activity window layout params of height and width:
WindowManager.LayoutParams params = getWindow().getAttributes();
params.x = ...;
params.y = ...;
params.width = ...;
params.height = ...;
this.getWindow().setAttributes(params);
To make a transparent background add to your activity definition in the manifest file:
android:theme="#android:style/Theme.Translucent"
That way, you can create the illusion of a floating activity:
Note that only the foreground activity will be resumed, while the background one is paused. But for most apps this shouldn't be an issue.
Now all that remains is when to launch the floating activity.
Here is an example of a "floating" calculator app using a regular activity. Note that the activity below the calculator belongs to another app.
What I would like to have is an activity indicator, which is displayed after my app is up and running, but while GWT is making AJAX calls.
For example have a look at following site : http://www.foodtrucksmap.com/#
Any ideas on how to achieve it?
You can use an activity indicator from here, they are animated gifs so you can display one like this:
<g:Image ui:field="activityImage"/>
MyResources resources = GWT.create(MyResources.class);
this.activityImage.setResource(resources.activityImage());
and in your resources interface you would set the image:
public interface MyResources extends ClientBundle{
// use the actual path to your image
#Source("../resources/images/activityImage.gif")
ImageResource activityImage();
}
When you make your async calls:
loadingImage.setVisible(true);
and in the callback:
loadingImage.setVisible(false);
I had to deal with the same kind of stuff few days back. The way I did was, created an Icon and Overlayed on the map.
Icon icon = Icon.newInstance("loading.gif"); // load you gif as icon
MarkerOptions options = MarkerOptions.newInstance();
options.setIcon(icon);
Marker indicator = new Marker(point, options);
So before the Async call and after you map is up, just add the icon to the map using
map.addOverlay(indicator);
and after the Async call remove the overlay using
map.removeOverlay(indicator);
I am not sure how correct this approach is, but this is what I did and it worked.