I want to ask you, if is possible in Android to make a control, which will take my own parameters.
I want, that my control will looks like:
<my.own.control
android:style
attributes
>
<include name=”” value=””>
<include name=”” value=””>
</my.own.control>
or
<my.own.control
Android:style
attributes
>
<include>
<name></name>
<value></value>
</include>
<include>
<name></name>
<value></value>
</include>
</my.own.control>
The reason why I want to do it this way, is to dynamically edit includes.
The most important question is, how to read includes on initialize.
Or do you have another advice?
Unfortunately this is not possible.
There is an open bug on the android project for it that was reviewed and accepted by Romain-gui, one of the lead android developers at google.
http://code.google.com/p/android/issues/detail?id=14532
There is however a workaround, it is explained very well at http://kevindion.com/2011/01/custom-xml-attributes-for-android-widgets/
Related
Okay as everyone somehow seems to think I asked how to create a fragment in xml, let me make this absolutley clear, using the attributes shown in the page that I keep ending up on.
Are there any more attributes that can be used in the <fragment> xml element than these?
<fragment
android:name=""
android:id=""
android:layout_weight=""
android:layout_width=""
android:layout_height=""/>
Looking under Android's R.styleable documentation, I see a bunch of Fragment-related values:
android:fragmentAllowEnterTransitionOverlap
android:fragmentAllowReturnTransitionOverlap
android:fragmentEnterTransition
android:fragmentExitTransition
android:fragmentReenterTransition
android:fragmentReturnTransition
android:fragmentSharedElementEnterTransition
android:fragmentSharedElementReturnTransition
android:id
android:name
android:tag
Search for Fragment_ and you'll see them. Unfortunately, I can't test them myself since I'm not near my IDE, but I think they are what you want.
There are 100+ layouts in a resource folder on android, I can go through them one by one and look at the preview in android studio. They all utilise code like:
tools:text="text for preview"
tools:visibility="visible"
Is there a way to inflate all those one after another in a list/linear layout? And upgrade the tools:xyz attribute to be shown as the real android:xyz attribute in this view
Context&Purpose: To show them in the app under a debug menu dedicated specifically to show available layouts. This is to communicate with both other developers and people without android studio.
I want to avoid doing it manually as it needs to be maintained and that can end very badly for debug functionality such as this. (And that it is a lot of layouts does not help either of course)
After writing it down it feels unlikely, but maybe someone out there have a nice angle on this?
Depending on the complexity of each layout, inflating a hundred of them at once could be quite taxing. You may run out of memory, or get a fair bit of jank. If you are OK with this, then I would say try using the include tag in your debug screen layout
A simple/naive implementation would be something like
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/A"/>
<include layout="#layout/B"/>
<include layout="#layout/C"/>
<include layout="#layout/D"/>
...
</LinearLayout>
I probably wouldn't recommend doing this, but it might get the job done.
As far as the second part of your question, using tools values as actual values, I don't think there is a way to accomplish this. In fact the tools values are not even available during run time as they are stripped out during the build process.
How can i include a preference.xml in a fragment that is in a tab?
All i want is the layout i have my own logic for settings, i just want the standard preferencescreen look.
This is my latest attempt.
<include layout="#xml/preferences"
android:id="#+id/rtes"
android:layout_height="match_parent"
android:layout_width="match_parent"
>
</include>
I thought this would be easier then to copy the look with a standart layout ...
android doesnt like to include layouts from the xml folder into layouts from the layoutfolder , i still think this should be possible but i couldnt find a way.
If anyone ses this question use this https://stackoverflow.com/a/30334930/6752994 and fake it... dumb i know ...
I am, at the moment, trying to make a google maps app using android studio.
Right now, everything is fine, except for one thing, when i go to the "Design" Tab, in the XML file i have this Redering message:
Rendering Problems A tag allows a layout file to
dynamically include different layouts at runtime. At layout editing
time the specific layout to be used is not known. You can choose which
layout you would like previewed while editing the layout...
And the main problem is that I cannot use any of the gui components in my layout, I searched about my problem and i understood that with this error, people couldn't see their map but they could put on textfields, widgets, layouts, etc.
But for me, my preview is completly frozen and i can't do any modification.
Picture of my android studio page.
As you can change the fragments dynamically with your code, android studio doesn't know which layout to show in design time. This is the reason of your error.
To specifically tell android which layout to show, add tools:layout="#layout/Your_layout_name" attribute to your fragment.
There is also a shortcut link below the error description which you have told. Just click on the link and android will add it for you and you will see the fragment in your layout with no rendering error messages.
For a detailed example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="com.example.insane.fragmenttest.MainActivity">
<fragment
android:id="#+id/testFragmentID"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.insane.fragmenttest.WorkOutDetails"
tools:layout="#layout/fragment_work_out_details" /> <!-- This is the line you want to add. -->
</LinearLayout>
Try using Designtime Layout Attributes. http://tools.android.com/tips/layout-designtime-attributes
These attributes guide Android Studio on how to render run-time attributes in the layout editor.
I think you should include tools:showIn="#layout/activity_maps" in your the <fragment> part of your google_maps_api.xml
Just use this design for the fragment. This solved my problem. Also, refer to this link
<fragment
android:id = "#+id/ma"
android:name = "com.google.android.gms.maps.SupportMapFragment"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
tools:context = "com.example.demomaps.MapsActivity"
/>
Yes I solved this easily..Simply ignore the message and click line that is showing below of the rendering messages.
Actually fragment contains layout inner and if its not include its showing warning that it must contains you can simply ignore this message below the warning then this rendering issue will be resolved.
After taking a look at theming for Fede's UberMusic I came across the file album_screen.xml. Below is the source of that file. Basically I noticed that his themes have the ability to use custom views that are a part of his application, and that they have this XML namespace at the top theme. I am missing the connection as to how he is able to apply his attributes to views that he does not control, and how Eclipse will compile the cod below without fail. I placed the URL http://schemas.uberdroidstudio.com/theme into my browser's address bar but nothing came up, and I cannot figure out where/ how Eclipse knows the attributes that the namespace supports. Thank you ahead of time for your help.
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:theme="http://schemas.uberdroidstudio.com/theme">
<TextView
android:id="#id/artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.0"
theme:textFilter="uppercase" /> <!-- This is the interesting line -->
I suspect that the theme:textFilter="uppercase" line isn't actually having an effect on the (apparently vanilla) TextView.
As for the URL of the namespace, it is interesting that you can't access it, since it does not appear to be a local styleable (Android would have you refer to a local styleable namespace as http://schemas.android.com/apk/res/your.package). +1 for novelty.
The solution is actually not as complicated as I originally thought. XML namespaces are arbitrary strings that just need to be unique. If your namespace does not start with http://schemas.android.com/apk/res then it is not validated and the APK package is not checked for declare-styleable or the like.
Now a custom namespace if very simple to implement, as illustrated by this code snippet in GitHub. Finally, applying custom XML attributes to "normal" widgets can be accomplished by using the LayoutInflater.Factory and calling setFactory before you inflate your views. Throw it all together and you have a highly theme-able, XML driven application like Fede's UberMusic.