Android Studio Java: setSystemUIVisibility cannot resolve symbol view - java

I'm developing an app using Capacitor js and trying to achieve an edge-to-edge display on Android. Unfortunately it looks like this requires knowledge about Android Studio and Java that I just don't have so I'm finding myself quite confused.
I found this documentation page, which tells me that to remove the black bar at the bottom of the screen I can either:
Add the following to my app styles:
<style name="AppTheme" parent="...">
<item name="android:navigationBarColor">#android:color/transparent</item>
<!-- Optional, but recommended for full edge-to-edge rendering -->
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
Which I've added in res/values/styles.xml, but which doesn't seem to be doing anythin (the black gesture bar is still there):
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:navigationBarColor">#android:color/transparent</item>
<!-- Optional, but recommended for full edge-to-edge rendering -->
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
Or, do it programmatically by calling:
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
I tried to add the above code to my MainActivity.java like this:
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import android.util.Log;
import android.view.View;
public class MainActivity extends BridgeActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
}
Unfortunately Android Studio is telling me that it cannot resolve symbol 'view'. I understand why that's happening since I have no reference to view in my class, but I'm unsure on how to get a reference to view at all.
I'm sure this can't be that complex, I'm just having a hard time understanding Android Studio and Java as I have very little experience with them. If anyone could point me in the right direction that would be great.
EDIT: Or is setSystemUI deprecated? Should I use this instead? I'm really lost

You can use the decorView() from your activity. View view = getWindow().getDecorView(). Also, note that this view can be null, so always check for null before using it.
Retrieve the top-level window decor view (containing the standard
window frame/decorations and the client's content inside of that),
which can be added as a window to the window manager.

Related

Why Design(activity_main.xml) and actual app look different?

i am new in Android development in java
my activity_main.xml file is look like this
But when i run this application in my pixel 3 phone than it's look's like
why this design are different ?
As seen in background, you ignore missing constraints. When working with ConstraintLayout you must provide at least one horizontal and one vertical constraint, otherwise views could jump, and I believe IDE gave u that error.
check your style file.
By default is with Dialog.
u can change it with No Dialog
Sorry i mean
the line
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
u can change the theme with no actionbar
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
there are many variants
if you want to have a full screen theme like Design(activity_main.xml):
solution 1: go into the manifest and use a full screen theme.
<activity
.
.
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
solution 2:
Just add the following attribute to your current theme:
<item name="android:windowFullscreen">true</item>
for example :
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/orange</item>
<item name="colorPrimaryDark">#android:color/holo_orange_dark</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
solution 3 :
public class MainActivity extends AppCompatActivity {
#Override
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);
}
}
and for manage your buttons, read Dorian's answer to Design and actual app look same.

Welcome Activity with background of image

I use the theme to show my WelcomeActivity
#android:style/Theme.NoTitleBar.Fullscreen
But I found it will have a period of black background when the app start
So I want to change the background of this theme
then I use...
<style name="WelcomeTheme" parent="#android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:windowBackground">#drawable/welcome_img</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
</style>
Although the background is changed , the Actionbar is also showing!!
the Actionbar doesn't show when I use Theme.NoTitleBar.Fullscreen
but it's showing when I use WelcomeTheme
how should I remove the ActionBar
Thanks for your help :)
-
By the way , in my WelcomeActivity extends Activity but not ActionBarActivity
Did you try one of those?
in Activity;
getActionBar().hide();
in Fragment;
getActivity().getActionBar().hide();
1. Make you welcome activity.
2. Go to styles xml file and create a style like that:
<!-- BWelcome application theme. -->
<style name="WelcomeTheme"
parent="android:Theme.DeviceDefault.NoActionBar.Fullscreen">
<!-- Customize your theme here. -->
</style>
3. Go to manifest file and add this to your welcome activity:
android:theme="#style/WelcomeTheme"
4. Add your welcome logo in an ImageView
5. Advice: Never use Java code if you can do it with XML
Hope it helps!
You can do this way:
WelcomeActivity extends ActionBarActivity:
on onCreate();
getSupportActionBar.hide();
In Layout file:
setBackground to Parent View:
Hope this will help you.

The following classes could not be instantiated: - android.support.v7.widget.Toolbar

I am creating an app with the new Material Design used in Android Lollipop (5.0).
I am using the following guides:
http://android-developers.blogspot.it/2014/10/appcompat-v21-material-design-for-pre.html
http://antonioleiva.com/material-design-everywhere/
After I create my toolbar, I receive this error: "The following classes could not be instantiated:
- android.support.v7.widget.Toolbar"
The app works well in the phone or emulator, but the layout designer of Android Studio doesn't show the layout correctly.
Here there are some images:
Error in my_awesome_toolbar.xml layout preview
Error in activity_my.xml layout preview
The xml code of the files:
my_awesome_toolbar.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
activity_my.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/root"
tools:context="com.myapp.test.MyActivity"
android:orientation="horizontal">
<include
android:id="#+id/toolbar"
layout="#layout/my_awesome_toolbar"
/>
<!-- Rest of layout -->
</RelativeLayout>
MyActivity.java:
package com.myapp.test;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MyActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
xml code of the styles (values/styles.xml):
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/blue</item>
<item name="colorPrimaryDark">#color/dark_blue</item>
<item name="actionOverflowButtonStyle">#style/AppTheme.OverflowButtonStyle</item>
</style>
<!-- Style Title -->
<style name="Title">
<item name="android:textColor">#color/white</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">16sp</item>
</style>
<style name="AppTheme.OverflowButtonStyle" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">#drawable/overflow_icon</item>
</style>
</resources>
At the moment I use Android Studio Beta 0.8.9
I changed the res/values/styles.xml file from this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to this:
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
and that solved the problem.
For Android Studio (or IntelliJ IDEA),
If everything looks OK in your project and that you're still receiving the error in all your layouts, try to 'Invalidate caches & restart'.
Wait until Android Studio has finished to create all the caches & indexes.
I did what #gbero said, and I changed the Android version number that Studio uses from 22 to 17 and it works.
I am using the backwards compatibility to build for Android ver 22 but to target 17 (idk if that's correctly said, I am still trying to figure this app stuff out) so that triggered the backwards compatibility, which afaik is what the android.support.v7.* is. This is probably a bug with their rendering code. Not sure if clearing the cache as suggested above was needed as rendering didn't work just after invalidating the cache, it started working after I changed the version to render. If I change back to version 22, the rendering breaks, if I switch back to 17, it works again.
From: https://stackoverflow.com/a/29989542/4123403
Clean project
Rebuild project
Sync Gradle
This did the trick for me.
Another mistake that can have the same effect can be the wrong theme in the preview.
For some reason I had selected some other theme here. After choosing my AppTheme it worked fine again:
Sorry if I answer myself, but, at the finally, the solution of my problem was update Android Studio to the new version 0.8.14 by Canary Channel: http://tools.android.com/recent/
After the update, the problem is gone:
I leave this question here for those who have this problem in the future.
Clean project
Rebuild project
Sync Gradle
it work for me
I did what #ang_lee said and also i added this line to the app theme style :
<item name="windowActionBar">false</item>
i am using version 26.0.1 :
com.android.support:design:26.0.1
com.android.support:appcompat-v7:26.0.1
building tools:
buildToolsVersion "26.0.1"
I had the same error on my Android Studio screen when i wanted to prevew my project. I fix the problem by this ways:
1- I chang the version from 22 to 21. But if I change back to version 22, the rendering breaks, if I switch back to 21, it works again. Thank you #Overloaded_Operator
I updated my Android Studio but not working. Thank you #Salvuccio96
I had the same problem for one of the activities in my app , one of the causes of this problem is that Theme in the theme editor might be different than the theme defined in the 'styles.xml'.change the Theme in the theme editor to your 'Apptheme' or your custom defined theme(if you have defined). Doing this fixed my issue.
none of above worked for me ,
i updated the appCompat - v7 version in my app gradle file from 23 to 25.3.1. helped to make it work for me
Find styles.xml in app/res/values folder.
Parent attribute of the style could be missing "Base".
It should start as
<style name="AppTheme" parent="Base.Theme.AppCompat...
I had the same error. Eventually I got this notice that a plugin was out of date:
After I updated, the problem went away.
The solutions above didn't help me. I've tried 2 first steps from
this link.
Worked fine for me.
But don't forget to
import com.melnykov.fab.FloatingActionButton;
instead of
import android.support.design.widget.FloatingActionButton;
in your MainActivity.java
I use android studio 2.3.3:
- Open styles.xml
- Android studio will show a notification on the top right with two options: "open editor" and "Hide notification".
- Click "open editor"
- Under theme parent dropdown, click show all themes
- Select any theme starting with AppCompat... (I used AppComat.DayNight)
NB: If your title bar disappears, you need to extend AppCompatActivity instead of Activity.
All the best!
My Problem has also been solved by changing in styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

How to set dialog (Custom) a glittering effect?

In my android app, I've designed some layouts to set the custom dialog. But I face some problems while making border with glittering effect.
I've set the following style to my dialog:
<style name="MyDialog" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowTitleStyle">#style/DialogWindowTitle</item>
<item name="android:windowFrame">#color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">#drawable/alertbgc</item>
In the java snippet,I added the lines as follows:
final Dialog mydialog= new Dialog(this,R.style.MyDialog);
mydialog.setContentView(R.layout.mylayout);
But with this snippets I'm getting very dark background (I used nine patch images too, but no use). Please help me providing your ideas.
Thanks in advance

Android action bar overlay & hidden by default in xml

I need to have the action bar hidden on application start. Then, after some user action, it has to show up again overlaying the content. Currently I turn it off in a custom style by setting <item name="android:windowActionBar">false</item>, and then call
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
getActionBar().hide();
in onCreate() of the activity.
That seems a little awkward though. Can I do all of it in xml configs?
I don't know about the hiding part, but you cna style the ActionBar as an overlay in your apps theme like this:
<style name="AppTheme" parent="#style/Theme.AppCompat">
<item name="android:windowNoTitle">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowActionBarOverlay">true</item>
</style>

Categories