Android Studio Render Title and Settings Missing - android

So I'm just making my first steps in Android Development and I got this problem I can't solve.
In the rendering part in Android Studio my default blank app doesn't show the title of the application or the default setting button but they do appear if I load the app on my phone or on the simulator. This is very weird and frustrating.
Why is this happening?
Code :
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

According to your question, please open the activity_main.xml file. You will see there:
<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>
It's your main activity toolbar, which screenshot you put there above. It has id, but it don't have any title. You can change it programmatically, but well, you won't see until you run an app on emulator or device.
This android.support.design.widget.AppBarLayout view comes from Google's Material Design. You can learn more about from ths site:
Introduction - Material Design - Google Design Guidelines
or by attending this free Udacity course:
Material Design for Android Developers
It allows you to create your own toolbar from a scratch (if you don't like existing). Take a look at this code:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="15dp"
android:text="That's great app!"
android:textSize="30sp"/>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
This changed view is also a toolbar with given name, but instead of Toolbar I used here LinearLayout with one TextView item.
I don't know if I answer your question, but please experimentize a bit with my changed code by adding for example an ImageView which would be a logo of your app or icon of settings.

Related

Themes giving dark menus?

I've done an app that works very well. A problem is that the menu has black text on dark background so it's hardly readable:
I think the menu colors are dependent on the theme used?
If so I guess the culprit is among these lines:
In manifest:
<application
android:theme="#style/Theme.MarinaMediterrania"
<activity
android:name=".MainActivity"
android:theme="#style/Theme.MarinaMediterrania.NoActionBar">
In activity_main.xml:
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:theme="#style/Theme.MarinaMediterrania.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/Theme.MarinaMediterrania.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
Anyone with an idea how to make the menu background more light or how to make the menu text color white?

Unable to add xamarin.forms.map control to Xamarin Form

I want to add a map control to my android app.
To do this I have got the latest xamarin.forms and xamarin.forms.maps packages from Nuget.
My code behind logic does nothing at all, and my axml page looks like as below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/optionsContainerLinearLayout">
//Other UI elements
<maps:Map>
</maps:Map>
</LinearLayout>
...
</LinearLayout>
Note I've but no tags within maps:Map so as to provide minimal chance for errors. Note that when I populate this map with more properties as directly below, the code still breaks in the same way:
<map:Map
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/mockMapView">
</map:Map>
When I run this application, it breaks on SetContentView() with the error:
Didn't find class "android.view.Map" on path: DexPathList
[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.geosolve.pavestate2-fJtHBLcT2gY6AlUrxcOOVg==/base.apk"],
nativeLibraryDirectories=[/data/app/com.geosolve.pavestate2-fJtHBLcT2gY6AlUrxcOOVg==/lib/x86, /data/app/com.geosolve.pavestate2-fJtHBLcT2gY6AlUrxcOOVg==/base.apk!/lib/x86, /system/lib]]
I've got another sample xamarin application I downloaded which runs fine on my emulator, so I don't think the emulator is the problem.
I have my API key being used by this other application as well, so I don't think the API key is the problem either.
My androidManifest.xml looks like so:
...
<application android:allowBackup="true" android:icon="#mipmap/icon" android:label="#string/app_name" android:roundIcon="#mipmap/icon" android:supportsRtl="true" android:theme="#style/GeosolveApp">
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="(My API Key)" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
...
Any help as to why this isn;'t just showing up like you would expect?
For Xamarin.Android,we usually install the Xamarin.GooglePlayServices.Maps package from NuGet.
And add the map in your xaml like:
Declaratively :
<fragment 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/map"
class="com.google.android.gms.maps.SupportMapFragment" />
Programmatically :
var mapFrag = MapFragment.NewInstance();
activity.FragmentManager.BeginTransaction()
.Add(Resource.Id.map_container, mapFrag, "map_fragment")
.Commit();
the more you could read Google Maps.

Spacing on AppBarLayout

Spacing on AppBarLayout and incomplete app bar title
on geny motion virtual mobile is ok
on all my mobiles problem
problem screenshot:
on virtual mobile ok screenshot:
activity_main.xml
<?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:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
app:tabMode="fixed"
android:layoutDirection="rtl"
app:tabGravity="fill"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</LinearLayout>
Try changing the style of the main activity (the one causing the issues) in the manifest, that should do it. You can check the default values when you create a new project using the "Basic Activity" template.
In this case since your layout contains a toolbar you should use the default theme (or a custom one to the same effect): android:theme="#style/AppTheme.NoActionBar". Notice that I´m using the default values of the template. The style you need should be something like this:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
This would be the manifest entry:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
BTW, just in case you havent done it, consider testing with the same API level in all devices (virtual and physical) to get consistent test results.
Hope it helps!

How to enable Split Action Bar?

I want to create an android application which has 3 sliding tab panel and each of them will 5 button (save,new,delete,exit..).
What I want is exactly as follow:
I created sliding tab panel.And for 5 button, I added split action bar.But It works as normal split action bar.My AndroidManifest.xml is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.belsoft.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:uiOptions="splitActionBarWhenNarrow"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Where is my wrong?
To implement splitActionBar:
Just add android:uiOptions="splitActionBarWhenNarrow" to your activity tag in theAndroidManifest.xml like this...
`<activity
android:name=".MainActivity"
android:uiOptions="splitActionBarWhenNarrow">`<br>
You can read more here and here
NOTE: It is available ONLY for handset devices with a screen width
of 400dp.
To create a custom bottom toolbar:
If you want to set it for all devices, please check my answer (find a post starting with Creating custom bottom toolbar) here:
Creating custom bottom toolbar
I've already created a simple app which should demonstrate you how to
begin
Creating a custom ViewGroup
Here's my activity_main.xml layout file:
<?xml version="1.0" encoding="utf-8"?>
<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:padding="0dp"
tools:context="com.example.piotr.myapplication.MainActivity">
<LinearLayout
android:id="#+id/show_pdf"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#color/primary_material_light"
android:orientation="horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_cut_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_copy_mtrl_am_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_selectall_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_paste_mtrl_am_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_share_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_selectall_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_moreoverflow_mtrl_alpha"/>
</LinearLayout>
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="75dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"/>
</RelativeLayout>
As you can see my parent ViewGroup is RelativeLayout, which simply
allows me to create a view at the bottom of screen.
Notice that I set layout padding to zero (I think: setting layout
margin to zero here is not necessary, the same effect). If you'd
change it, the toolbar won't use full width and it won't stick with
bottom of the screen.
Then I added a Linear Layout with hardcoded height which is:
android:layout_height="40dp"
I wanted it, that my bottom toolbar would take full available width so
I set it as match_parent.
Next, I added some ImageButton views with images from Android
library.
There you have two possibilities:
if you really want to have a toolbar like in above example just remove in every ImageButton view this line:
android:layout_weight="1"
After removing weights and some buttons you would get a view pretty
similar to expected:
if you want to take the full width and make every button with the same size use in your project weight as in this mine example.
Now let's go to my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.piotr.myapplication"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateVisible|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
In that file I'd added as you can see only one additional line:
android:windowSoftInputMode="stateVisible|adjustResize">
to make sure that device keyboard won't hide my custom bottom toolbar.
From: How to add a bottom menu to Android activity
If you have any question please free to ask.
Hope it help

Error Binary XML file line #2: Error inflating class on android programming

I have an android program with 2 layouts. The first layout is Login. When the login is started first, I have no problem. When I try to change in AndroidManifest from login to splash layout, I got an error. The error is like the title of this posts.
In this android manifest, I change my code from :
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".Login"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
to :
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Here is the layout for login:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".Login">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your total is 0"
android:textSize="45dp"
android:gravity="center"
android:id="#+id/tvDisplay"
/>
<Button
android:layout_width="250dp"
android:layout_height="100dp"
android:text="Add One"
android:gravity="center"
android:layout_gravity="center"
android:id="#+id/bAdd"
android:textSize="20dp"/>
<Button
android:layout_width="250dp"
android:layout_height="100dp"
android:text="Substract One"
android:gravity="center"
android:layout_gravity="center"
android:id="#+id/bSub"
android:textSize="20dp"/>
And here the layout of splash:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/sertifikat"
tools:context=".Splash"></LinearLayout>
And structure of my code :
Log in logcat:
Here splash.java
How can I fix my code?
Hey You missed some small things
Here is a small example from your code
on Github that i wrote
This is running example of your code
Other than the ending tags
The <intent-filter>
should only be one
most probably the problem lies in your #drawable
as well as look at these tutorials they are great
http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/
Obviously,you have lost a character '/' in the splash layout at the end.
You are missing the closing tag of your LinearLayout in splash.xml. Add </LinearLayout> to the end of the file. You also might want to consider using an ImageView with android:scaleType="centerCrop" instead of using a LinearLayout with a background. Using android:background will stretch to fit the size of the screen, which can give a different aspect ratio on different devices, whereas an ImageView will scale it to maintain the aspect ratio (depending on the scaleType).
Also, a LinearLayout is not appropriate for a single image, since it is meant to be a container for other views.
For better performance I recommend you to follow this :
http://www.cutehacks.com/blog/2014/01/13/splash-screens
If you use an high end device you won't see a big difference, but for common devices you will see an huge improvement

Categories

Resources