I am having problem with invoking a custom component in my Android projects in Eclipse. It seem that I do not understand how the namespace declarations belong together. I have checked several other threads here at SO, which at first seem to be related, but I cannot solve my problem with these:
android-custom-control-namespace-issue
how-to-pass-custom-component-parameters-in-java-and-xml
android-custom-widget-styles-how-to-put-them-into-a-namespace
I have the following set-up (code is anonymized):
/values/extra_attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="extraComponent">
<attr name="count" format="integer" />
</declare-styleable>
</resources>
/layout/extra_main.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="#+id/extra_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/extra_main"
/>
</merge>
/com.site.package.extra/extra.java
package com.site.package.extra;
... misc imports...
public class Extra extends FrameLayout
{
... misc code...
}
/com.site.package/main.java (start-up class)
package com.site.package;
... misc imports...
public class Main extends Activity
{
... misc code...
}
/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/main_style"
xmlns:extra="http://schemas.android.com/apk/res/com.site.package" >
<com.site.package.Extra
android:layout_width="wrap_content"
android:layout_height="wrap_content"
extra:count="3">
</com.site.package.Extra>
</RelativeLayout>
The problem I face is; whatever I do, I cannot manage to invoke my custom component. The errors occur in may layout and I have tried to change the following items:
name space declaration
xmlns:extra="http://schemas.android.com/apk/res/com.site.package"
xmlns:extra="http://schemas.android.com/apk/res/com.site.package.extra"
xmlns:extra="http://schemas.android.com/apk/res/extra"
component invokation
<com.site.package.extraComponent />
<com.site.package.Extra.extraComponent />
<extraComponent />
<Extra.extraComponent />
<android.view.ext.extraComponent />
attributes
extra:count="3"
com.site.package.extra:count="3"
In neither case I manage to get any help from intellisense so I am completely lost. I really do not understand how the namespaces are working here and how I should put the code to work.
EDIT :
I forgot to include my AndroidManifest.xml file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.site.package"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_logo"
android:label="MyApp"
android:name="MyApp" >
<activity
android:label="MyApp"
android:name=".Main" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</manifest>
Your custom component is situated in the package com.site.package.extra(from the code you posted) so you could use it in the xml layout with:
<com.site.package.extra.Extra // ... other attributes
or with:
<view class="com.site.package.extra.Extra"
// ... other attributes />
The namespace for the custom attributes:
xmlns:extra="http://schemas.android.com/apk/res/com.site.package"
and to use them:
extra:count="3"
Related
I made my first app today on my phone using an application named "A.I.D.E".
How can I remove my app name and label from the top of the main screen? I named my app "YT Studio", but I don’t want to show this name and label on top of my main screen. I want it to be blank. How can I do it?
I provided the android manifest.xml and main.java file for the reference.
File android manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ojhastudios.ytstudio" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="YT Studio"
android:theme="#style/AppTheme"
android:resizeableActivity = "true">
<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>
File main.xml
<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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" />
</LinearLayout>
The code:
package com.mycompany.myapp;
import android.app.*;
import android.os.*;
public class MainActivity extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getSupportActionBar().hide();
}
}
You can just call
getSupportActionBar().hide();
in your activity's onCreate() method.
The method given above does not work when using an Android 10 activity. It works with AppCompatActivity.
So, this answer will do the task.
In your AndroidManifest.xml, find your activity and then you should add this line in it:
<application>
...
<activity
android:name=".MainActivity"
android:theme="#style/Theme.MaterialComponents.Light.NoActionBar">
...
</activity>
...
</application>
Go to src/main/res/values and open file theme.xml:
Then change your style name to NoActionBar. It removes your action bar:
Go to res → values → themes
<style name="Theme.MyAppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
...
...
</style>
Change it to Theme.MaterialComponents.Light.NoActionBar. The magic here is the NoActionBar and your toolbar will be removed completely, including the app title name. But you should know this, after you change it, it’s going to be removed from your entire project, not just the single activity.
How can I open an Activity at the start of a widget to set the required settings?
The idea is to on putting a widget on the main screen to be able to define which i.e. the working database through an index.
To start some activity right after put widget on screen, it's enough to define in the manifest with this intent-filter:
<activity android:name=".ConfigurationActivity">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
</activity>
then add android:configure entry in AppWidgetProviderInfo metadata:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:configure=".ConfigurationActivity"
android:initialLayout="#layout/widget_layout"
android:minHeight="50dp"
android:minWidth="50dp"
android:updatePeriodMillis="50000" />
I want to modify an existing file with FreeMarker.
For Ex,
<?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="$(package_name)">
$(activities)
<activity android:name=".map.activity.MapsDemoActivity" />
<activity android:name=".map.activity.MapListActivity" />
<activity android:name=".map.activity.EventsDemoActivity" />
<activity android:name=".map.activity.InfoWindowDemoActivity" />
<activity android:name=".map.activity.CustomMarkerClusteringDemoActivity" />
</manifest>
In above code I want to update the $(package_name) and $(activities).
I'm using org.freemarker:freemarker:2.3.23, Need to do this file modification using Java program.
I know how to create new file using free maker but unable to modify existing file using java program.
Please suggest any solution.
Use merge command in the recipe.xml
<merge from="root/src/AndroidManifest.xml.ftl"
to="${escapeXmlAttribute(manifestOut)}/AndroidManifest.xml" />
In root/src/AndroidManifest.xml.ftl
you just specify the elements that you want to insert
I would like to use a Google Map in my current application. Before integrate it to my app, I created a test project to understand the functionalities.
I read this : https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api
and this :
http://developer.android.com/google/play-services/setup.html#
After a lot of problems with these errors :
didn't find class com.google.android.gms.maps.MapFragment
and
Found 2 versions of android-support-v4.jar in the dependency list,
but not all the versions are identical (check is based on SHA-1 only at this time)
When I run my project, Eclipse says "Launching Test:(99%)", then my computer temperature up to 100°C and Eclipse take 512% of my CPU ! So I'm obliged to force Eclipse to quit.
I spent a lot of time on stack overflow, rebuild, clean, add support library, delete project and recreate from the beginning etc.
Help me, I just want to create a basic app to test a GoogleMap !
My code :
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.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.MapFragment"/>
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="***" />
</application>
</manifest>
Edit : I know now that the problem appears when I reference the google-play-services_lib to my project... Any ideas ?
public class YourActivity extends FragmentActivity {
GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_activity);
map =((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.iqamah_map)).getMap();
}
}
your xml :
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/iqamah_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment" />
Add this in your Manifest
<uses-permission android:name="com.example.test.permission.MAPS_RECEIVE" />
<uses-library android:name="com.google.android.maps" />
Even me having the same issue, then instead of getting API key from Google Map Android V2, i took the API key from Google Maps Embed API and included in the Manifest and solved my problem.
Proof:
1.API key i took for project
2.Used Key in Manifest.xml
[WARN] For your density-specific images
(android/images/high|medium|low|res-*)
to be effective, you should put a
element with
anyDensity="true" in the
section of your
tiapp.xml or in a custom
AndroidManifest.xml
I get this warning in my emulator. Now where do i add <supports-screens> in my tiapp.xml
<?xml version="1.0" encoding="UTF-8"?>
<ti:app
xmlns:ti="http://ti.appcelerator.org">
<id>com.gfg.gfgfg</id>
<name>fgfgfgf</name>
<version>1.0</version>
<publisher>uuuu</publisher>
<url>http://www.uuu.com</url>
<description>No description
provided</description> <copyright>2011
by John</copyright>
<icon>default_app_logo.png</icon>
<persistent-wifi>false</persistent-wifi>
<prerendered-icon>false</prerendered-icon>
<statusbar-style>default</statusbar-style>
<statusbar-hidden>false</statusbar-hidden>
<fullscreen>false</fullscreen>
<navbar-hidden>false</navbar-hidden>
<analytics>true</analytics>
<guid>cba0a3f5-1d77-4cb2-bac0-4fb27109f48b</guid>
<iphone>
<orientations device="iphone">
<orientation>Ti.UI.PORTRAIT</orientation>
</orientations>
<orientations device="ipad">
<orientation>Ti.UI.PORTRAIT</orientation>
<orientation>Ti.UI.UPSIDE_PORTRAIT</orientation>
<orientation>Ti.UI.LANDSCAPE_LEFT</orientation>
<orientation>Ti.UI.LANDSCAPE_RIGHT</orientation>
</orientations>
</iphone>
<android xmlns:android="http://schemas.android.com/apk/res/android">
</android>
<modules></modules>
</ti:app>
Im not sure what file you are showing but the supports-screens value is set using the manifest file; which (I believe) needs to be called AndroidManifest.xml.
Here is the full details: http://developer.android.com/guide/topics/manifest/supports-screens-element.html
A manifest file usually looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dsfdsfds.dasdsa"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".dsfdsfds"
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>
<supports-screens android:anyDensity="true" />
</manifest>
And <supports-screens> can be put anywhere inside <manifest>
Can someone back me up here though; does the posters XML look like a manifest file for android?