I'm not sure why when I run my emulator, everything in my Layout XML doesn't appear but the emulator only shows everything that is in my Menu Xml.
Hope someone can help. Thank you
(Using Android Studio)
The layout xml is:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.zainuddeen.myapplication.Main2Activity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/fab_margin"
android:src="#android:drawable/ic_dialog_email" />
and menu xml is:
<?xml version="1.0" encoding="utf-8"?>
<item
android:id="#+id/action_search"
android:title="#string/action_search"
android:icon="#drawable/ic_search_black_48dp"
app:showAsAction="ifRoom|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView"/>
<item
android:id="#+id/action_favorite"
android:icon="#drawable/ic_favorite_black_24dp"
android:title="#string/action_favorite"
app:showAsAction="ifRoom"/>
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never"/>
<item android:id="#+id/action_share"
android:title="#string/action_share"
app:showAsAction="ifRoom"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>
I think you design different xml and run different
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
put the name of layout in R.layout.mylayout
Related
I converted my website into an Android web-view using an empty activity. The only issue I'm having right now is displaying my website pages in the form of a menu in the navigation drawer. Please assist me in achieving this.
Here is my Layout Activity-main.xml code
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout 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:id="#+id/swipeRefreshLayout"
tools:context="com.developer.arsltech.MemberPortal.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:layout_width="match_parent"
android:layout_height="9dp"
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_marginTop="-2dp"
android:progress="20"
android:visibility="gone"
/>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/myWebView"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:id="#+id/relativeLayout">
<ImageView
android:layout_width="240dp"
android:layout_height="240dp"
android:src="#drawable/no_internet"
android:layout_centerHorizontal="true"
android:id="#+id/noConnectionLogo"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Internet Connection"
android:layout_below="#+id/noConnectionLogo"
android:textAlignment="center"
android:textSize="26sp"
android:id="#+id/txtNoConnection"/>
</RelativeLayout>
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
Please assist me in achieving this.
If i put the button before appbar it does not show up. If i put it inside, it shows up but it does not fit properly (height is under imageview and the two can not be in the same height). I tried different layouts other than coordinatorlayout and it hapens again there too.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:alpha="1"
tools:context=".MainActivity">
<ImageButton
android:id="#+id/search_button"
android:layout_width="55.5dp"
android:layout_height="55.5dp"
android:layout_marginLeft="298.5dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_baseline_search_24" />
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<ImageView
android:id="#+id/title"
android:layout_width="155dp"
android:layout_height="55.5dp"
android:minHeight="?actionBarSize"
android:src="#mipmap/ic_banner_foreground" />
<com.google.android.material.tabs.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:tabGravity="center"
app:tabMode="auto" />
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="59dp"
android:layout_marginTop="672dp"
android:background="#color/colorPrimary"
android:theme="#style/AppTheme.AppBarOverlay">
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="566dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ListView
android:id="#+id/list_view"
android:layout_width="match_parent"
android:layout_height="566dp" />
</androidx.viewpager.widget.ViewPager>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
It is not showing because you've used "#android:color/transparent" as background for your ImageButton. Chose another color and it will be visible. Or just add some text so that you can see it.
I'm working on a project in Android Studio. I created a Navigation Drawer project, using 16 as my minSdkVersion. My Notification bar has a strange shadow (this is my AppBar) and I want to have material design's notification bar (this is Material Design's Appbar).
Default code is:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?
<android.support.v4.widget.DrawerLayout
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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" /
</android.support.v4.widget.DrawerLayout>
app_bar_main.xml
<?xml version="1.0" encoding="utf-8
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true"
tools:context="com.ingsoft.url.gudbox.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
android:background="#android:color/transparent"
android:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" /
</android.support.design.widget.CoordinatorLayout>
I've found similiar questions like this, but they didn't help.
Thanks!
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context="com.yossikally.hello.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<!--<android.support.design.widget.FloatingActionButton-->
<!--android:id="#+id/fab"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="bottom|end"-->
<!--android:layout_margin="#dimen/fab_margin"-->
<!--android:src="#android:drawable/ic_dialog_email" />-->
</android.support.design.widget.CoordinatorLayout>
I built the simplest hello world project.
In the xml design pane I get what's in the picture
Tried to change themes and change version. Get the same
please add to your App gradle file Android Design Support Library:
compile 'com.android.support:design:23.+'
How do I have textview on top of my listview (code shown below)? I tried many ways of placing the textview but it just does not appear.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:gravity="center_horizontal"
android:id="#+id/nameheader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ListView
android:gravity="center_horizontal"
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
In your code just add android:text="Maulik Dodia". I have just copy your code added TWO LINES to it. One is above one, Second is android:entries="#array/names". I have also added <string-array name="names">
<item>Maulik</item>
<item>Maulik1</item>
<item>Maulik2</item>
<item>Maulik3</item>
</string-array> to strings.xml
And It worked for me in preview of Android Studio as well as in Emulator.
Below is my code as well as Screen Shots.
activity_main.xml
<?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:orientation="vertical"
tools:context="com.XXXXXXXXXX.sotestingapp.MainActivity">
<TextView
android:id="#+id/nameheader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Maulik Dodia"/>
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="#array/names"
android:gravity="center_horizontal"></ListView>
</LinearLayout>
strings.xml
<resources>
<string name="app_name">SOTestingApp</string>
<string-array name="names">
<item>Maulik</item>
<item>Maulik1</item>
<item>Maulik2</item>
<item>Maulik3</item>
</string-array>
</resources>
Hope this help.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_parent"
android:orientation="vertical"
>
<TextView
android:gravity="center"
android:id="#+id/nameheader"
android:text="Hello Android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
Please check this if it works.