How to fix android...ViewPager in Android Studio - android

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.

Related

Layout that appears and disappears completely when the application is launched

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

Android Studio XML Widgets not rendering properly in designer

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

Total beginner; need help properly setting up my Android 5.0 Toolbar

I do have a toolbar right now, but I don't really understand a lot of the things that I needed to add and copypaste from tutorials and other questions to get it to work. Also, my toolbar doesn't display an elevation even though I set android:elevation to 9dp.
Similar to the Google I/O app, I've set up a resource in /layout for my toolbar. I copied the name and named it "toolbar_actionbar_with_headerbar". Please excuse that it doesn't make any sense.
This is the content:
toolbar_actionbar_with_headerbar.xml
<?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="128dp">
<Toolbar
android:id="#+id/toolbar"
android:elevation="9dp"
android:layout_height="128dp"
android:layout_width="match_parent"
android:minHeight="?android:attr/actionBarSize"
android:background="?android:attr/colorPrimary"
android:gravity="bottom" />
</LinearLayout>
Now, as it's apparently supposed to be done, I am applying my toolbar to activities by including them in their /layout XML-file. Works fine.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
[...]
<include layout="#layout/toolbar_actionbar_with_headerbar" />
[...]
</RelativeLayout>
However, this is my first question. When I did that initially, my toolbar was cut off at the sides like all other content of the activity, according to the margins set at the beginning of the xml. Right now, I simply deleted those, and add margins for every text field and other things on the activity. There probably is a better way?
The second question is: Why doesn't my elevation work? I've even tried setting it through code onCreate, but that doesn't work either. And lastly, what would I have to do to properly support devices pre-Level21?
Thanks a lot.
You should read this post: appcompat-v21
Take care when you copy some code text, there are some ” that are wrong, and you should change to ".
About elevation (you can read it in the post too), it only works with lollipop.

How to create Listview like android L's recent App listview

I known about use of RecycleView and CardView but i want to create Listview that can work like android L Recent App listview .
You can check from this link .
below is screen shot of android 5.0 recent app list.
You can use carousal libraries like
http://code.google.com/p/carousel-layout-android/ which allows creating vertical carausal.
Or atleast you can have idea from the source code.
As Mohammad Khatri said you can use
http://code.google.com/p/carousel-layout-android/
and change the activity_main.xml to
<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"
tools:context=".MainActivity"
android:background="#android:color/darker_gray">
<!-- <com.touchmenotapps.carousel.simple.HorizontalCarouselLayout
android:id="#+id/carousel_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"/> -->
<com.touchmenotapps.carousel.simple.VerticalCarouselLayout
android:id="#+id/carousel_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
To complete previous answers (as I cannot comment),
In order to make http://code.google.com/p/carousel-layout-android/ work in vertical mode, you need 2 things :
In activity_main.xml, comment the HorizontalCarouselLayout and uncomment VerticalCarouselLayout
In MainActivity.java, comment the block dealing with HorizontalCarousel* and uncomment the one dealing with VerticalCarousel*
However, it doesn't work exactly like the recent apps display, since each swipe makes you move only one item in the list (there is no "fling" effect).

Blank screen on SlidingMenu when using with Fragment (GMap)

So i use SlidingMenu library with a FragmentActivity in my app.
There is a GoogleMap in the layout and a menu on the left side with some content.
When i pull the menu to see it, there is a big black rectangle there, covering my sliding menu content. After i click it once, it is disapearing.
Can anybody has something to say about this?
I had the same issue on android 2.3.7 but not in 3.x or later versions. After rotating the view the menu renders fine after.
I found a solution using a custom TransparentSupportMapFragment from: Android MapView With Sliding Menu Obscures Menu
Fragment Black screen issue
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
<!-- hack to fix ugly black artefact with maps v2 -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent" />
</FrameLayout>
This is a known problem.
You may want to have a look at these issues:
http://code.google.com/p/gmaps-api-issues/issues/detail?id=4639
http://code.google.com/p/gmaps-api-issues/issues/detail?id=4659
Maybe you can find a workaround in comments there.
I know this question is too old but since I come here by chance and see there is no accpeted answer I will answer this.Hope it help someone someday.
My solution is add a light layout (about 1dp) with transparent background above the "Shopradar" layout of yours. This worked for me,hope it works for you too ;)

Categories

Resources