When the application is launched, my layout is displayed for a very short second and then disappears. As a beginner in Kotlin, I don't understand why it produces this result.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="univ.master.kotlin.weather.city.CityFragment">
<fragment
android:id="#+id/city_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="univ.master.kotlin.weather.city.CityFragment"/>
</LinearLayout>
It's just a message from the preview window telling you that it can't show a preview for the fragment tag due to not knowing what kind of fragment you'll insert. When you run your actual app, the fragment will render fine.
try to add :
tools:layout="#android:layout/YOUR_LAYOT"
<fragment
android:id="#+id/city_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#android:layout/YOUR_LAYOT"
android:name="univ.master.kotlin.weather.city.CityFragment"/>
Thank you for sharing your xml and java code. If you tried everything and still layout is not appring it is just because of android studio is not able to catch you .xml code not to worry.
You can Select all xml code ctrl+A>ctrl+X>ctrl+V Don't ask me how.
I don't even know how but it works for me. You can also try this because this is the android studio universal rule
Rebuild project or Clear catch and restart
Hope it helps
Related
Recently, while working on some projects, I've had a rather annoying problem when coding the user interface of my application. The problem is, some controls (usually a floating action button or a regular button) render strangely. It's hard for me to explain exactly how it looks - but here's an example of how it shows the floating action button to look like in the designer:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:baselineAligned="false"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".MainActivity">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:src="#drawable/ic_baseline_add_24"
android:layout_height="wrap_content"/>
</LinearLayout>
Now, the thing is, I don't have any weird or special code added, the XML code is as pure as it gets, so I have no idea why I am having these strange rendering problems.
Here is how it rendered the following button:
Code:
<com.google.android.material.button.MaterialButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_gravity="bottom"
android:textAllCaps="false"
android:layout_margin="30dp"
app:cornerRadius="30dp"
android:id="#+id/submitButton"
android:backgroundTint="#color/turquoise"
/>
Image:
A solution would be greatly appreciated!
Cheers,
Tom
Solution is simple u just need to restart your android rendering engine. I provided Image for your context . In android studio top right corner above layout display there is Toggle issue panel click on that and u will see one box in the bottom showing rendering issue restart rendering engine and that will restart your android studio. and u good to go. try this solution and let me know your issue is solved or not.
note: In my Image I already restarted so there is no option for restart rendering engine .but in yours's U may be find hope so.
Image
I currently making a messaging app for my school project. I'm just starting mobile development this semester. Currently have run into a problem where when I add android ViewPager my activity_main.xml shows:
On the preview of the activity_main.xml
android...ViewPager (in blacktext in grey brackground)
For further explanation:
Anyway I was just thinking of following along to a tutorial because i'm stiil not that capable enough to code but are proffessor still told us to make an app even though his not really teaching that much. That's why i dont understand anything at all.
I just went to this tutorial and decided to use it for my whole project since i dont know anything at all.
So I went and watch and followed along a playlist on how to make a messaging app on this youtube channel Coding cafe, this is currently the video I'm watching and following:
https://www.youtube.com/watch?v=3Am-iad_Gkg&index=5&list=PLxefhmF0pcPmtdoud8f64EpgapkclCllj
First Project:
The first few tutorials everything was fine but at video number 5
Ive' watch the whole video did everything he did but after running the app if you see on his video the tabs were working on his but not on mine I just saw the title of my app but the tabs were not showing at all.
I tried looking at my work then i saw my xml file and there goes the:
click to see image
On the preview of the activity_main.xml
android...ViewPager (in blacktext in grey brackground)
I didn't know what to do because i was stupid did not know what to search, I search android...ViewPager, viewpager in android studio not working but all i was getting was "how to make a appbartab" and other tutorials on how to make one but i was afraid since this project is due february I' really rushing.
New Project Redo:
Back to the problem so after that i did not know what to do so I went and redo the project. Followed his tutorial again then I noticed that my problem was in the viewpager itself in the xml file.
When I typed the:
android View pagerin my activity_main.xml
It showed this again:
On the preview of the activity_main.xml
android...ViewPager (in blacktext in grey brackground)
so I was like what do i need to do?
So in the "First Project:" I already finished coding and doing everything he did in the video really carefully and as said it did not work
In "New Project Redo:" my progress is up until this point (timestamp 3:16)
I was afraid of going further because this code (see it on the video timestamp 3:16)
Made my activity_main preview do this:
On the preview of the activity_main.xml
android...ViewPager (in blacktext in grey brackground)
I dont know what the problem is so I really need help.
This is my code, as i've said havent add the fragment or anything yet cause i redid the project my progress is still in video 5 (timestamp 3:16).
Refer to the video for more information some people also have this problem in the comments but there are no replies.
https://www.youtube.com/watch?v=3Am-iad_Gkg&index=5&list=PLxefhmF0pcPmtdoud8f64EpgapkclCllj
If anyone can help me then thank very much.
My activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorAccent"
tools:context=".MainActivity">
<include
android:id="#+id/main_page_toolbar"
layout="#layout/app_bar_layout">
</include>
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout
android:id="#+id/main_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/main_tabs_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/appBarLayout">
</android.support.v4.view.ViewPager>
</RelativeLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity
{
private Toolbar mToolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar= (Toolbar) findViewById(R.id.main_page_toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("Chatterfly");
}
}
app_bar_layout.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/main_app_bar"
android:background="#color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
</android.support.v7.widget.Toolbar>
I expect to have my app have an actual app bar where which has chats groups and contacts in it. Which right now isnt showing up when I run the app it only shows the Title of my app.
You need to add tab into your tab layout in order to show tab there by doing somehting like this tabLayout.addTab(tabLayout.newTab().setText(title));
As reference you can also look at this code, you can ignore the fragment adapter add the moment if you don't need it at the moment.
I have installed all sdk and correctly installed but I have tried multiple times but I cannot fine frame of app where I can insert tool,widgets, button, etc. (Cannot add anything on workspace)
My Android studio window image: https://drive.google.com/file/d/0B8AWJ5JO_e0xVV9KVEE0TUpMYWc/view?usp=drivesdk
Select devices,sdk and theme,like this
image: https://drive.google.com/open?id=0B7VdJKtF9NwGNVFKeE5zZ2pxVHM
Looks like you've gotten rid of the Component Tree.
Try go to the Text-tab and paste
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
or whatever root layout you need...
After doing a lot of research, and not finding anything... quick question, does anybody has an idea why Android Studio is not taking the Map tag? The code below is a fragment of the maps sample in the SDK. Already added google play services lib and support, but nothing.
It's showing the error
Unexpected namespace prefix "map" found for tag fragment.
Thanks a lot in advance!
<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
map:cameraZoom="10" />
I had the same problem once I've been moving the map fragment into FrameLayout (so I could add a button on top of the map).
I don't know what I've really done as I'm a noob in Android apps and XML, but it looks that I found the solution :-)
I tried to make the trick including the fragment from a separate file (using 'include' directive) and once I put the bare map fragment without any namespace definitions it proposed me 2 options:
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:map="http://schemas.android.com/tools"
I realized that maybe the 2nd one will work in the original file (although in original file Android Studio is not proposing it, but only the 1st one instead).
Conclusion:
Just change this line:
xmlns:map="http://schemas.android.com/apk/res-auto"
with this:
xmlns:map="http://schemas.android.com/tools"
AS I MENTIONED - I'M A NOOB AND MAYBE MY SOLUTION GOT SOME SIDE EFFECTS SO PLEASE LET ME KNOW IF SO (although everything seemed to be working fine by so far...).
That's my working map layout with a button on the top and no errors:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/tools"
tools:context="com.maverickrider.myapp.inviteActivity.MapsActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/purpura_E51B4A">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
map:cameraTargetLat="51.513259"
map:cameraTargetLng="-0.129147"
map:cameraTilt="30"
map:cameraZoom="13"
/>
<Button
android:id="#+id/startActivityButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:onClick="cokolwiek"
android:text="Baton z dupy"
android:layout_alignParentBottom="true"
/>
</FrameLayout >
I had this problem as well. I did Project/Clean and the error went away and it works fine now. This assumes that the map namespace is properly defined above where it's being used.
I'm running 0.5.8 and the XML viewer is underlining the attrs with map: - however the app is building fine. YMMMV.
I am trying to add a background to my android project. Heres the code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backround="#drawable/awesome_face">
</RelativeLayout>
I spelled everything out correct but when i go into my graphical layout after saving and nothing shows up. Furthermore after i cleaned the project I now have an error on the
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
saying "no resource identifier found for attribute background in package 'android'" Anyone have ideas?
Just like ChristopheCVB said, your backgroud tag is missing a G.
android:backGround="#drawable/awesome_face">