Android Framework modification : Adding a custom layout - android

I am trying to add a new layout to the framework say my_layout.
I succeeded partially in that .
I defined my layout in an xml and put it inside frameworks/base/core/res/res/layout
I then mentioned the id in frameworks/base/core/res/res/values
public.xml and ids.xml
And after performing a complete build :
make framework
make update-api
make
i am able to access it as android.R.layout.my_layout
But now i want to access it through xml also :Eg: "#android:layout/my_layout"
In which place in the source do i mention this reference ?

Try to declare the id in your my_layout.xml file in your layout folder.
for example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
...
Happy coding :)

Related

Xamarin Android Style Xml Attributes

in the layout xml files that we create . we sometimes use '#' & '?' attribute what does it mean
For e.g i created toolbar.xml . i could see the ?android:attr/actionBarSize what does this mean
& what does #android:style/**ThemeOverlay.Material.Dark.ActionBar" mean
<?xml version="1.0" encoding="utf-8"?>
<Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="**?android:attr/actionBarSize**"
android:background="**?android:attr/colorPrimary**"
android:theme="**#android:style/**ThemeOverlay.Material.Dark.ActionBar"/>
If you read the document about ResourcesFromCode, you will find
if you use #..., that means a syntax to reference a resource in an XML resource:
#[<package_name>:]<resource_type>/<resource_name>
And if you use ?..., that means you are referencing a style attribute and the resource type portion is optional:
?[<package_name>:][<resource_type>/]<resource_name>
You can get more examples and detailed information in the document.
And here is a link that may help: question-mark-in-xml-attributes-for-android

layout_width is missed after using <android.support.v4.widget.SlidingPaneLayout> tag

I'm new to Android development and trying to learn it by the book Android for Absolute Beginners
One of the chapters is about android U.I Design and i'm learning about different android layouts in this chapter .
My problem starts after adding <android.support.v4.widget.SlidingPaneLayout > Tag to my code in order to use android SlidindPaneLayout .
Before Adding this Tag I could use android:layout_width or android:layout_height and ... attribute in all of objects . But now it can be only used inside my sliding layout tag
Here is a little simplified version of my code which as you can see android:layout_width is not used inside Linear Layout because Eclipse doesn't accept it ;)
for more detail look at the link below Please ;)
<?xml version="1.0" encoding="UTF-8"?>
<android.support.v4.widget.SlidingPaneLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="hamid.traingin.hellouniverse.MainActivity"
android:id="#+id/spLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:orientation="horizontal"
android:background="#drawable/milkyway1">
</LinearLayout>
</android.support.v4.widget.SlidingPaneLayout>
Here is a picture of my problem in Eclipse IDE:
The xml code is valid, you can and should add the layout_width and layout_height to you LinearLayout without raising a compiler error. I'm not too sure why Eclipse does not allow you to do so, but Android Studio does:

The meaning of sentence in head of XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
When I made android application, I see sentence in head of XML File. But I don't know the meaning of it.
I assume you are talking about
<?xml version="1.0" encoding="UTF-8"?>
http://www.w3schools.com/xml/xml_tree.asp
Quoting from the link above
The first line is the XML declaration. It defines the XML version (1.0).
Also check
http://en.wikipedia.org/wiki/UTF-8
<LinearLayout xmlns:android="schemas.android.com/apk/res/android";
Its a LinearLayout that you have in xml
xmlns- its xml name space
A quick search on the same topic on stackoverflow gives the below links which should anser your question
Why this line xmlns:android="http://schemas.android.com/apk/res/android" must be the first in the layout xml file?
What does "xmlns" in XML mean?
I think you are talking about this line <?xml version="1.0" encoding="utf-8"?>
That line actually defines the version of .xml file.
Please refer to XML Standards
In xml Header this is ?xml version="1.0" the xml VERSION you are defining. This is the ENCODING TYPE of xml to be defined encoding="utf-8"? . And this is the NAMESPACE of xml xmlns:android="http://schemas.android.com/apk/res/android" hope this help.

Error: No grammar constraints (DTD or XML schema) detected for the document

I have a problem with this xml file as said in the title.
I dont know how to solve the problem as i have already searched a lot and only found answers like use clean or change validation of this type to ignore
none of the above worked as i want to clear this problem so that my R will be generet in the gen folder.
Hope someone can see the problem soon as this is my examprojekt im working on and cant get further without solving this error :)
<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"
tools:context=".Dekrypter" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world" />
</RelativeLayout>
Start your XML with:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE RelativeLayout>
The solution is to put on the top of xml this code. It identify the type of the document to encode!
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
Revalidate the project!
CIAO!!!
I retrieve a solution from a bug issue :
Click Window > Preferences > XML > XML Files > Validation
Change the setting 'validating files'>'No grammar specified' from warning to ignore.
Re-validate your project. No more warnings now.
It works for me.
Add
<?xml version="1.0" encoding="utf-8"?>
To the top of your XML file. This tells the parser that your file is indeed an XML, that it should use XML version 1.0, and that you are using utf-8 encoding.
Without it, the parser doesn't know how it should parse your XML.
First put this :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
and after that do this structure:
Click Window > Preferences > XML > XML Files > Validation
Change the setting 'validating files'>'No grammar specified' from warning to ignore.
Re-validate your project. No more warnings now.
thank you AntoineP and TecnoHelp83
https://stackoverflow.com/a/19314230/3117196
https://stackoverflow.com/a/22973854/3117196
worked as well

xml file vs xml layout

I created two layout files.
Android XML Layout File which created this xml
<?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" >
</LinearLayout>
and an Android XML File
<?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" >
</LinearLayout>
From the looks of it they are both the same. When to use one over the other since they are both creating the same xml?
Yeah they are prograticaly the same, there isn't different type of xml. What matters, is the location of the xml (layout, values, ...).
In eclipse, there maybe is a small difference in the IDE view, i'm not sure that you have the Graphical Layout view if you create a Android XML file instead of a layout file (it's a detail because, you still can add this view ;) )
But results apk will be identical.
The reason why you would use an Android XML, is if you wanted to use the Layout Tool (the GUI layout editor). The Eclipse IDE will react to this file differently.
But, the code is the same, so the APK you create will also be the same - it doesn't matter in your final output.
I always use Android XML files, so they integrate into the ADT tools better.
the only difference as far as I can see is that in xml you can't use both "android:layout-width:" and "android:layout-height:" attributes which makes xml for example suitable for the use of menu and item bar and other uses.

Categories

Resources