Android Studio RC 4 ActionBar doesnt appear in preview - android

Im creating a new project from 0 but when i see the preview doesnt show any actionBar , im just creating it from 0 i dont have any code,
a Picture: http://i.stack.imgur.com/CaeE1.png
here is my style.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
And my 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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
And my MainActivity.java:
package com.example.jorwys.myapplication;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
But when i open a older project the preview does show me the actionbar so i think the problem is the new android studio; Thank you for the help. im sorry about my bad english.

This Preview is only for your Layout Components. So if you wanna see there something you have to add it in your Layout Code. You could For Example add a sort of View you and take Acces of it in your Activity and change it as you like.

I noticed that was compiling with API 21 (Lollipop) so i change it to API 19 ( Kitkat) and also the appcompat library from: compile 'com.android.support:appcompat-v7:21.0.+' to compile 'com.android.support:appcompat-v7:20+'

Related

I want to publish geosever layer in android app, using arcgis SDK, i have done code but it is not working, please tell me what i am doing wrong?

I am doing Android programming for the first time, I want to display a GeoServer layer using the ArcGis SDK map layer. I have done the code but it is not working, please tell me what i am doing wrong.
activity_main.xml
<?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:id="#+id/activity_main"
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="com.example.subrata.mymap.MainActivity">
<com.esri.android.map.MapView
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
mapoptions.MapType="Aerial"
mapoptions.center="28, 77"
mapoptions.ZoomLevel="10">
</com.esri.android.map.MapView>
</RelativeLayout>
mainactivity.java
package com.example.subrata.mymap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.esri.android.map.MapView;
import com.esri.android.map.ogc.WMSLayer;
public class MainActivity extends AppCompatActivity {
MapView mMapView;
WMSLayer wmsLayer;
String wmsURL;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMapView = (MapView)findViewById(R.id.map);
wmsURL = "http://localhost:8081/geoserver/NFR-SR/wms";
wmsLayer = new WMSLayer(wmsURL);
wmsLayer.setImageFormat("application/openlayers");
// available layers
String[] visibleLayers = {"NFR-SR:Ridgeline_SR"};
wmsLayer.setVisibleLayer(visibleLayers);
wmsLayer.setOpacity(0.5f);
mMapView.addLayer(wmsLayer);
mMapView.setEsriLogoVisible(false);
mMapView.enableWrapAround(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Can't really tell what you mean by not working without any log or explanation.
Here are some possible reason:
cannot reach server at url http://localhost:8081/geoserver/NFR-SR/wms
layer name NFR-SR:Ridgeline_SR not found
map service doesn't support application/openlayers
It could even be it is working but you are viewing the map extent which does not contain any data.

button to show an image android app

I would like to make a simple app with a button that shows a picture when pressed.
Here is what I've written.
manifest:
<?xml version="1.0" encoding="utf-8"?>
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".MainActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:theme="#style/AppTheme"
android:name="Activityfullscreen"></activity>
</application>
main:
package com.mycompany.button_show;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button_send);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent inf=new Intent(MainActivity.this,Activityfullscreen.class);
startActivity(inf);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
.java for the second activity:
public class Activityfullscreen extends AppCompatActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_screen);
ImageView img = (ImageView) findViewById(R.id.widget45);
img.setBackgroundResource(R.drawable.aa);
}
}
activity_main:
<?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" >
<Button
android:id="#+id/button_send"
android:layout_width="fill_parent"
android:layout_height="120dp"
/>
<TextView
android:id="#+id/widget45"
android:layout_width="fill_parent"
android:layout_height="120dp"
/>
</LinearLayout>
activity full screen:
<?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="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/widget45"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
styles:
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light">
<!-- Customize your theme here. -->
</style>
When I run, everything is fine, but when I launch the app I get the following error:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
Where is my mistake?
In Style.xml, you need to use AppCompat Theme - (RECOMMENDED)
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.AppCompat.Light">
<!-- Customize your theme here. -->
</style>
The above theme is Material Light theme.
Otherwise, you can leave AppCompat(But I don't recommend this as AppCompat is used for Material themes for lower Android versions like Jellybean, Honeycomb and Gingerbread) by using this code in Main - (NOT RECOMMENDED)
public class MainActivity extends Activity { // Changed from AppCompatActivity to just Activity
... Enter the code you use here
}
Change this too if you use the NOT RECOMMENDED method -
public class Activityfullscreen extends Activity { // Changed from AppCompatActivity to just Activity
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_screen);
ImageView img = (ImageView) findViewById(R.id.widget45);
img.setBackgroundResource(R.drawable.aa);
}
If you like this answer, please mark it as selected.
PS - Material.light is available only on Android 4.4 (Kitkat) +

Could-not create the view: org.eclipse.pde.runtime.LogView

I am new to Android and building a small test program and the program is not running and giving me Could not create the view: org.eclipse.pde.runtime.LogView error
here is the code from my android_main.xml file
<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="com.example.myapplication.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
Here is the java code from MainActivity.Java
package com.example.myapplication;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
I apologize that I am posting this as an answer instead of a comment, but commenting requires 50 reputation and I don't have that yet. Can you post your java code too? The problem is likely in there, it may be the method by which you are loading the view.

android project not resolving and reseting androids studio doesn't work

I have a problem where files that should be showing up in my android project are not appearing. For example, in the following code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_gravity="bottom|left"
android:orientation="horizontal"
>
<ImageButton
android:id="#+id/pencil"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="left"
android:src="#drawable-mdpi/pencil"
/>
<ImageButton
android:id="#+id/eraser"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:src="#drawable-mdpi/eraser"
/>
</LinearLayout>
I get errors for the pencil and eraser src lines, despite having the two bitmap images in that exact folder (and being able to see it in my directory). Similar problems exist for this code:
import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class DrawingActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawing);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(res.menu.drawing, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == res.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Where it cannot find drawing.xml (at line with res.menu.drawing), even though again it is visible in the directory.
Is there something else I'm supposed to do first? Maybe some kind of import beyond putting the items in the folder and rebuilding? I've read in some other cases that these kinds of problems were resolved by exiting and re-opening Android Studio, but I've now done that twice with no effect (as well as multiple cleans and rebuilds of the project). As such, I can only assume that I'm missing something more essential.
Any help would be greatly appreciated.

Android Layout does not display controls

I am writing my first android app after reading a tutorial. I am excited and thought its easy. However, after adding a simple edit text and a hello world message, i run and was expecting to see something yet nothing showed up. Neither the textbox nor the default hello world. Pls where do go wrong ? Below is my layout (i.e 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:paddingLeft="16dp"
android:paddingRight="16dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:textColor="#FF00FF00"/>
<EditText android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textColor="#FF0000FF"
android:id="#+id/et_Text" />
</RelativeLayout>
My java code is the default/code generated one. I was expecting to see atleast the message for a start yet didn't show any control. Just a screen with a phone dialers on the rigth hand.
package com.example.mytest;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Since you are using RelativeLayout, you need to tell Android how each control is relative to each other. Change the layout as follow:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:id="#+id/textView1"
android:textColor="#FF00FF00"/>
<EditText android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="#+id/textView1"
android:textColor="#FF0000FF"
android:id="#+id/et_Text" />
This will tell the system to place the EditText below the TextView.

Categories

Resources