Android studio navigation bar toolbar - android-studio

i followed one of the tutorials in creating navigation bar in android studio. But in the end i the result i got was that then i click item in the navigation bar it closes instantly without taking any action and changing fragment.
you can slide it to the side and open but whenever i am trying to push item to trigger some kind of action even toast it doesn't work. it just closes to the side like it doesn't react to any action.
public class TrackerActivity extends AppCompatActivity implements LocationListener, NavigationView.OnNavigationItemSelectedListener {
private DrawerLayout drawer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tracker);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//Menu kad matytume kuris pazymetas
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
//first time opening activity if statement is for rotating screen so it wouldn;t reload
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new TruckTrailerRegistrationFragment()).commit();
navigationView.setCheckedItem(R.id.nav_truck_trailer_registration);
}
}
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.nav_truck_trailer_registration:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new TruckTrailerRegistrationFragment()).commit();
break;
case R.id.nav_list_orders:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ListOfOrdersFragment()).commit();
break;
case R.id.nav_information:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new InformationFragment()).commit();
break;
case R.id.nav_logout:
Toast.makeText(this, "logout", Toast.LENGTH_SHORT).show();
break;
}
drawer.closeDrawer(GravityCompat.START);
return true;
}
// We don't want to leave activity when menu is open we want to close it
#Override
public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
Drawerlayout main activity it has some other things like textview which currently doesn't work so i haven't posted that
``` <?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"
android:screenOrientation="portrait"
tools:context=".TrackerActivity"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
app:menu="#menu/drawer_menu" />```
Drawer_menu.xml
``` <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_truck_trailer_registration"
android:icon="#drawable/ic_truck_trailer"
android:title="Register transport" />
<item
android:id="#+id/nav_list_orders"
android:icon="#drawable/ic_list_of_orders"
android:title="List of orders" />
<item
android:id="#+id/nav_logout"
android:icon="#drawable/ic_logout"
android:title="Logout" />
<item
android:id="#+id/nav_information"
android:icon="#drawable/ic_information"
android:title="Information" />
</group>
</menu>```
androidManifest.xml file haven't changed anything
```
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.bachbachbach.trucktracker">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".TrackerActivity"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>```
styles.xml file
```
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>```
Any help would help.

Related

Menu does not appear in the actionbar(android studio kotlin)

Hi guys I can't get my dropdown menu to show up in my action bar.
In the menu.item.xml, the menu bar appears in the menu split view, however upon loading it on the emulator the menu disappears.
I can't find any solutions in the existing forums on StackOverflow.
Menu.item.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/miProfile"
android:icon="#drawable/ic_action_name"
app:showAsAction="ifRoom"
android:title="Profile"
android:iconTint="#color/white"
>
<menu>
<item
android:id="#+id/menuSortNewest"
android:title="Sort by newest" />
<item
android:id="#+id/menuSortRating"
android:title="Sort by rating" />
</menu>
</item>
</menu>
Main activity implementation of the onOptionsItemSelected
override fun onOptionsItemSelected(item: MenuItem): Boolean{
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.fragmentContainerView) as NavHostFragment
val navController = navHostFragment.navController
return when (item.itemId) {
R.id.menuSortNewest -> {
navController.navigate(R.id.action_home2_to_hamster)
true
}
R.id.menuSortRating -> {
navController.navigate(R.id.action_home2_to_dog)
true
}
else -> super.onOptionsItemSelected(item)
}
}
Toolbar in the activitymain.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="90dp"
app:titleTextColor="#android:color/white"
android:background="#color/black"
android:gravity="center"
>
</androidx.appcompat.widget.Toolbar>
</LinearLayout>

Android Studio (AS) 4.1 Kotlin Portrait to Landscaoe does not work

Having read and tested numerous threads here to this topic (most threads to Java, not to Kotlin), I do not succeed in realizing and do not understand, what i do wrong
This is my Portrait test layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<TextView
android:id="#+id/myText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="this is my Portraittext"
tools:layout_editor_absoluteX="173dp"
tools:layout_editor_absoluteY="344dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
I created landscape-xml by "create landscape.." This is the landscape-file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<TextView
android:id="#+id/myText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="this is my Portraittext"
tools:layout_editor_absoluteX="173dp"
tools:layout_editor_absoluteY="344dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
My Kotlin-file is quity simple:
package com.example.mytest
import android.content.res.Configuration
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.TextView
import android.widget.Toast
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
Toast.makeText(this,"in portrait", Toast.LENGTH_SHORT).show()
} else {
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this,"in landscape", Toast.LENGTH_SHORT).show()
}
}
}
}
The Configuration does not change nor does any of the 2 "Toast"-statements fire. (In debug mode the onConfigurationChanged function is not entered
My AndroidManifest.xml is this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mytest">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.MyTest">
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="uiMode|orientation|screenSize|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This means : quite standard, only extension the
android:configChanges="uiMode|orientation|screenSize|keyboardHidden">
I checked several entries in this line with orientation, screenSize, uiMode....., but nothing works. When I force the landscape-mode directly, display goes to landscape as expected.
What is wrong with my code?
I want to close my question. It works now without any change on my smartphone, but not in the emulator. May be strange, Sorry

Adding an app bar to a bottom navigation activity

I want to add an app bar to my app which has a bottom navigation bar. I followed the android developer's help and here is what I made in my activity:
public class BetsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bets);
BottomNavigationView bottomNavigationView = (BottomNavigationView)
findViewById(R.id.navigation);
bottomNavigationView.setOnNavigationItemSelectedListener
(new BottomNavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
Fragment selectedFragment = null;
switch (item.getItemId()) {
case R.id.navigation_p1:
selectedFragment = p1.newInstance();
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
break;
case R.id.navigation_p2:
selectedFragment = p2.newInstance();
myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
break;
}
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frame_layout, selectedFragment);
transaction.commit();
return true;
}
});
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frame_layout, p1.newInstance());
transaction.commit();
}
Activity's layout:
<RelativeLayout
android:id="#+id/activity_main"
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="com.example.carbet.BetsActivity">
<FrameLayout
android:id="#+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/navigation"
android:animateLayoutChanges="true">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
app:itemTextColor="#android:color/white"
app:itemIconTint="#android:color/white"
app:menu="#menu/navigation" />
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
</RelativeLayout>
And here is my app manifest:
<application
android:allowBackup="true"
android:icon="#mipmap/logo_car_bet"
android:label="#string/app_name"
android:roundIcon="#mipmap/logo_car_bet"
android:supportsRtl="true"
android:theme="#style/AppTheme.NoActionBar">
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#mipmap/logo_car_bet" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorAccent" />
<activity
android:name=".MainActivity"
android:label="Car Bet"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".BetsActivity"
android:label="#string/title_activity_bets"
android:parentActivityName=".MainActivity"/>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</application>
I use fragments for the bottom nav bar but I don't do anything in their files.
When I launch it, first it shows a green bar, but without any title nor overflow menu. When I go to the other fragment, title appear but not the menu.
Please tell me which error(s) I made.
Add an AppBarLayout with ToolBar within in the xml
and in Java code, Add this after setContentView
Toolbar toolbar=findViewById(R.id.your_toolbar_id)
setSupportActionBar(toolbar);
and then inflate your Menu.

How to set background color of Android ListView entries/items?

I have a ListView with entries that have a lighter background color than the application's layout, and I don't know why.This is a snapshot with red arrows indicating the difference in color: Main_Activity
I have no idea where to start on this.
This is the manifest.xml file that takes up the theme, AppTheme:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gtfp.workingmemory"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<!-- Start an Alarm When the Device Boots if past due -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".appController"
android:launchMode="singleTop"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".editToDoItem"
android:theme="#android:style/Theme.Holo.Dialog" >
</activity>
<receiver android:name=".ToDoAlarm">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity
android:name=".AlarmActivity"
android:theme="#android:style/Theme.Holo" >
</activity>
<activity
android:name=".SettingsActivity"
android:theme="#android:style/Theme.Holo" >
</activity>
</application>
</manifest>
That theme in fact is Theme.Holo in the resources file:
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<!-- <style name="AppBaseTheme" parent="android:Theme.Holo.Light"> -->
<style name="AppBaseTheme" parent="android:Theme.Holo">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>
This is the main layout for the application you'll see the ListView here:
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="${relativePackage}.${activityClass}">
<ListView
android:id="#+id/lvToDos"
android:layout_width="206dp"
android:layout_height="380dp"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:smoothScrollbar="false"
android:layout_above="#+id/itemEntryView"
android:layout_alignParentTop="true"
>
</ListView>
<LinearLayout
android:id="#+id/itemEntryView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true">
<Button
android:id="#+id/btnNewToDo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="editToDoItem"
android:text="#string/new_item"
android:textSize="#dimen/smallTextSize"/>
</LinearLayout>
</RelativeLayout>
Each row in the ListView is as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:gravity="center"
android:id="#+id/container"
android:layout_height="?android:attr/listPreferredItemHeight"
>
<ImageView
android:id="#+id/priorityImage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scaleType="center"
android:focusable="false"
android:clickable="true"
android:layout_marginLeft="5sp"
android:layout_marginRight="5sp"
android:src="#drawable/low"
/>
<TextView
android:id="#+id/itemText"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:focusable="false"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textAlignment="center"
android:textStyle="bold"
/>
<TextView
android:id="#+id/itemDueDate"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_marginRight="5sp"
android:scaleType="center"
android:textSize="12sp"
android:focusable="false"
android:textStyle="bold"
android:gravity="center"
/>
</LinearLayout>
It seems that you want to change the background color of your list view if this is the case then you can easily do this in your custom listview base adapter you can do it in your base adapter's getview Method.
here is the sample code
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView == null)
{
convertView = new TextView(ListHighlightTestActivity.this);
convertView.setPadding(10, 10, 10, 10);
//here I am changing the color of text in textview
((TextView)convertView).setTextColor(Color.WHITE);
}
convertView.setBackgroundColor((position == curSelected) ?
Color.argb(0x80, 0x20, 0xa0, 0x40) : Color.argb(0, 0, 0, 0));
((TextView)convertView).setText((String)getItem(position));
return convertView;
}
or alternatively if you know the idea of using selector then you can easily achieve it through selector.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="#color/BackgroundColor" />
<item android:drawable="#color/transparent" />
</selector>
I am sure your problem would get solved in these two above mentioned solutions. Use any of them, which ever is easy for you.
Set app color in list view
<ListView
android:id="#+id/lvToDos"
android:layout_width="206dp"
android:layout_height="380dp"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:smoothScrollbar="false"
android:background="#color/app_color"
android:layout_above="#+id/itemEntryView"
android:layout_alignParentTop="true"
>
</ListView>
I found the problem.
In the getView, I'm producing 'rounded corners' for every item in the ListView by setting their resource background to a customized drawable:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
:
:
:
:
convertView.setBackgroundResource(R.drawable.rounded_corner);
}
Well, in the drawable, I found there was a solid colour being drawn in there. I commented it out, and now I get what I want:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- <solid android:color="#433E41"/> -->
<corners android:radius="5dp" />
<padding android:left="3dp" android:top="3dp" android:right="3dp" android:bottom="3dp" />
<stroke android:width="3dp" android:color="#E6E6E6"/>
</shape>`enter code here`
I just happened upon this while investigating another matter (I hate porgramming). Appreciate your efforts regardless.

Google Maps API V2 showing blank white screen on mobile

I made an app using Lynda's tutorial of Building Mobile Apps Using Google Maps API V2(http://www.lynda.com/Android-tutorials/Building-Mobile-Apps-Google-Maps-Android-API-v2/133347-2.html).
I am stuck on Chapter 2 ( Creating You First Map) . I followed each and everything but still my device shows a blank screen with Google Written in Bottom Left Corner and Zoom In and Zoom Out buttons.It looks like it is not able to load the map.
MainActivity.java
package com.example.map;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import android.os.Bundle;
import android.app.Dialog;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends FragmentActivity {
private static final int GPS_ERRORDIALOG_REQUEST = 9001;
GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(servicesOK()){
Toast.makeText(this, "Ready To Map!",Toast.LENGTH_SHORT ).show();
setContentView(R.layout.avtivity_map);
}
else{
setContentView(R.layout.activity_main);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public boolean servicesOK(){
int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if(isAvailable == ConnectionResult.SUCCESS){
return true;
}
else if(GooglePlayServicesUtil.isUserRecoverableError(isAvailable)){
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
dialog.show();
}
else{
Toast.makeText(this, "Can't Connect",Toast.LENGTH_SHORT ).show();
}
return false;
}
}
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission android:name="com.example.map.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.example.map.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.example.map.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBdhCuM37w_myIbi87dMDwRnwd383UwXSk" />
</application>
</manifest>
Avtivity_map.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
Activity_main.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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
Please help me solve this. Why aren't maps coming on screen.
I am making a Google Science Fair project in which this app has a role to play.
Any help will be appreciated.

Resources