Creating App Name with subscript not working flutter - android

So I want to make my app name as App5 so I did the following. I went to andriod/app/src/AndriodManifest.xml and edited this file to
android:label="#string/app_name"
And then went to andriod/app/src/res/values/strings.xml and Added my app name as following
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">App<sub><small>5</small></sub></string>
</resources>
But still the subscript isn't working so what did I do wrong

Here your app_name's string is considered to be containing text 'App' and child object sub, that's why it isn't working and you are getting only App instead of App5.
Try instead escaping this <sub><small>5</small></sub> by encapsulating it inside <![CDATA[<sub><small>5</small></sub>]]> so you will have :
<string name="app_name">App<![CDATA[<sub><small>5</small></sub>]]></string>
OR
using html entities and
<string name="app_name">App<sub><small>5</small></sub></string>
(PS : check if your widget accepts and formats html)
UPDATE
I forgot to add < at the beginning and > at the end of ![CDATA[]]
, It has been corrected above
In your activity onCreate method do like this ( using the app_name above)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
//ADD THIS LINE
setTitle(Html.fromHtml( getResources().getString(R.string.app_name)));
...
}

Related

Xamarin Forms - XAML ContentPage error "No Property of name Id found"

So I'm trying to get this app off the ground so I can actually start putting functionality in it and it's failing to load the first page.
I'm getting a XamlParseException when it attempts to LoadFromXaml in the generated class.
Error message is "No Property of name Id found"
public partial class ProxDefaultPage : ContentPage {//This is a generated class
private ActivityIndicator Discoverying;
private void InitializeComponent() {
this.LoadFromXaml(typeof(ProxDefaultPage));//error thrown here
Discoverying = this.FindByName<ActivityIndicator>("Discoverying");
}
}
Here's the XAML markup of the page in question
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
Id ="cpDiscovery"
x:Name ="Discovery"
xmlns ="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.Droid.DefaultPage">
<ActivityIndicator
Id ="aiDiscovering"
IsRunning="true"
Color ="Blue"
x:Name ="Discoverying" />
</ContentPage>
What am I missing in the markup that isn't getting parsed?
set the x:Name before you set any other attribute
After a quick run to the Xamarin forums, I got an answer.
http://forums.xamarin.com/discussion/32014/cant-load-basic-contentpage-xamlparseexception-no-property-of-name-id-found
Turns out, the generated class does not use a property named "Id", or the property named "Id" does not match the type of data provided. Having this attribute in the xaml markup caused the error.
By removing the Id attribute from the ContentPage, the page finally ran successfully.

How to include a string resource in XML format accessible in every *.cs file?

As my title says, how do I include a resource string in XML format that I can access by its id? This id is auto generated in dot42 but I can't find any teachings in Google.
Create a new file strings.xml with this content:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="firstName">MisterFive</string>
</resources>
Include it in your project and set the Build Action property to 'ValuesResource'.
If you open R.cs (inside properties folder), you will see that the following code is generated:
//------------------------------------------------------------------------------
// This file is automatically generated by dot42
//------------------------------------------------------------------------------
namespace dot42Application2
{
using System;
public sealed class R
{
public sealed class Strings
{
public const int firstName = 0x7f040000;
}
}
}
You can access your string resource from C# like this:
string firstName = GetString(R.Strings.firstName);
NM! Just figure it out again.
For anyone who came into this problem, just go to:
Solution Explorer > Project(Right Click) > Add > New Item > Dot42 > Android > String table resource > Build (Press F7) > Done!

How to copy element from one xml to another xml with python

I have 2 xmls (they happen to be android text resources), the first one is:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="TXT_T1">AAAA</string>
</resources>
and the second is
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="TXT_T2">BBBB</string>
</resources>
I know the attribute of the element that I want to copy, in my example it's TXT_T1. Using python, how to copy it to the other xml and paste it right behind TXT_T2?
lxml is the king of xml parsing. I'm not sure if this is what you are looking for, but you could try something like this
from lxml import etree as et
# select a parser and make it remove whitespace
# to discard xml file formatting
parser = et.XMLParser(remove_blank_text=True)
# get the element tree of both of the files
src_tree = et.parse('src.xml', parser)
dest_tree = et.parse('dest.xml', parser)
# get the root element "resources" as
# we want to add it a new element
dest_root = dest_tree.getroot()
# from anywhere in the source document find the "string" tag
# that has a "name" attribute with the value of "TXT_T1"
src_tag = src_tree.find('//string[#name="TXT_T1"]')
# append the tag
dest_root.append(src_tag)
# overwrite the xml file
et.ElementTree(dest_root).write('dest.xml', pretty_print=True, encoding='utf-8', xml_declaration=True)
This assumes, that the first file is called src.xml and the second dest.xml. This also assumes that the element under which you need to copy the new element is the parent element. If not, you can use the find method to find the parent you need or if you don't know the parent, search for the tag with 'TXT_T2' and use tag.getparent() to get the parent.
This will work only for your simple example:
>>> from xml.dom.minidom import parseString, Document
>>> def merge_xml(dom1, dom2):
node_to_add = None
dom3 = Document()
for node_res in dom1.getElementsByTagName('resources'):
for node_str in node_res.getElementsByTagName('string'):
if 'TXT_T1' == node_str.attributes.values()[0].value:
node_to_add = node_str
break
for node_res in dom2.getElementsByTagName('resources'):
node_str3 = dom3.appendChild(node_res)
for node_str in node_res.getElementsByTagName('string'):
node_str3.appendChild(node_str)
if 'TXT_T2' in node_str.attributes.values()[0].value and node_to_add is not None:
node_str3.appendChild(node_to_add)
return dom3.toxml()
>>> dom2 = parseString('''<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="TXT_T2">BBBB</string>
</resources>''')
>>> dom1 = parseString('''<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="TXT_T1">AAAA</string>
</resources>''')
>>> print merge_xml(dom1, dom2)
<?xml version="1.0" ?><resources>
<string name="TXT_T2">BBBB</string><string name="TXT_T1">AAAA</string></resources>

Appcelerator Titanium Internationalization not working right

Here's one that's driving me crazy:
I have recently started looking into Appcelerator Titanium. I have built a few small apps both with a normal project and using Alloy so I understand the basics at least.
One thing I just cannot get working is the i18n folder/files.
Here is what ive done:
- Create a "Default Project"
- add folder to root directory "i18n"
- add "en" and "es" folder to "i18n"
- add "strings.xml" to both those new folders.
- added:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="welcome_message">Welcome TEST</string>
</resources>
to both the strings.xml, except in the es strings I put "ES Welcome TEST".
- In Resources -> app.js I changed "I am Window 1" to L('welcome_message')
- Ran the application
Both the normal and alloy versions just show a blank screen. I would like to get my alloy app working the most but from what I understand the localization code should work the same in both apps. In alloy I may just have to put it in the style.
Any pointers would be great! I have looked at other post claiming its not working but all of them were either syntax errors or just set it up wrong. I have copied their code and have the exact same issue with it not working so I have a feeling im missing a newbie step.
-- Here are some screenshots, I just created a brand new regular(not alloy) project, added the code above and try to use L('welcome_message') to no luck. I tried installing everything on a new PC to make sure I wasn't messing anything up on my main computer.
Heres the answer:
https://wiki.appcelerator.org/display/guides/Internationalization
Ends up by default your manifest file is not setup by default to allow localization UNLESS you choose a tabbed project.
Kinda silly if you ask me.
For the topic poster:
My new string.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="welcome_message">Don't Help Austin</string>
<string name="user_agent_message">user agent set to</string>
<string name="format_test">Your name is %s</string>
<string name="base_ui_title">Base UI</string>
<string name="controls_win_title">Controls</string>
<string name="phone_win_title">Phone</string>
<string name="platform_win_title">Platform</string>
<string name="mashups_win_title">Mashups</string>
<string name="ordered">Hi %1$s, my name is %2$s</string>
</resources>
Screenshot of my non-Alloy experiment:
For those looking to answer the question in the topic, this is a possible answer below.
My i18n folder is on the same hierarchy level as app and plugins, so mine isn't inside the app folder like the rest of the Alloy resources.
index.xml
<Alloy>
<Window class="container">
<Label id="label" onClick="doClick"></Label>
</Window>
</Alloy>
index.tss
".container": {
backgroundColor:"white"
},
"Label": {
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#000",
text: L("welcome_message")
}
strings.xml
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="welcome_message">Welcome to Kitchen Sink for Titanium</string>
<string name="user_agent_message">user agent set to</string>
<string name="format_test">Your name is %s</string>
<string name="base_ui_title">Base UI</string>
<string name="controls_win_title">Controls</string>
<string name="phone_win_title">Phone</string>
<string name="platform_win_title">Platform</string>
<string name="mashups_win_title">Mashups</string>
<string name="ordered">Hi %1$s, my name is %2$s</string>
</resources>
When I placed the L("welcome_message") inside the index.xml, it didn't work.

How to place hyperlink to a website on android app?

I want to place a hyperlink on android app that I am developing.
I tried this:
main.xml
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/hyperlink"
android:id="#+id/hyperlink"
android:autoLink="web"
>
</TextView>
The strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">WebLink</string>
<string name="hyperlink">http://google.com</string>
</resources>
But the problem is, the link looks like this: http://google.com and I don't want to show the actual url.
1) How to replace link by text like "Click Here to visit Google" and the text is linked with the website url ?
2) How to place email address (same question, how to replace it with text something like "Click Here to Email" and the text should be linked with email#domain.com)
I also tried this tutorial: http://coderzheaven.com/2011/05/10/textview-with-link-in-android/
But I am getting following error messages:
Description Resource Path Location Type
http cannot be resolved to a variable MyLink.java /MyLink/src/com/MyLink line 21 Java Problem
Syntax error on token "" <br /> <a href="", ? expected after this token MyLink.java /MyLink/src/com/MyLink line 21 Java Problem
Type mismatch: cannot convert from String to boolean MyLink.java /MyLink/src/com/MyLink line 20 Java Problem
Use the default Linkify class.
Here is an Example and the code from the tutorial:
This is my sample code for you, I think this will solve your problem:
public class StackOverflowActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 1) How to replace link by text like "Click Here to visit Google" and
// the text is linked with the website url ?
TextView link = (TextView) findViewById(R.id.textView1);
String linkText = "Visit the <a href='http://stackoverflow.com'>StackOverflow</a> web page.";
link.setText(Html.fromHtml(linkText));
link.setMovementMethod(LinkMovementMethod.getInstance());
// 2) How to place email address
TextView email = (TextView) findViewById(R.id.textView2);
String emailText = "Send email: Click Me!";
email.setText(Html.fromHtml(emailText));
email.setMovementMethod(LinkMovementMethod.getInstance());
}
}

Categories

Resources