Font Awesome Convert into a number in android - android

Here i have to create a one button in which i want to write string as well as create a icon .
I used the font-awesome and font-tello but in both of them i facing a problem in out put the the icon is converted into a number format any one give solution.
Thank You in advance..
MainActivity.java
Typeface newFont = null;
Button cameraBtn = null;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
cameraBtn = (Button)findViewById(R.id.button1);
newButton = Typeface.createFromAsset(getAssets(), "fonts/fonta.ttf");
cameraBtn.setTypeface(newButton);
cameraBtn.setText(R.string.icon);
}
string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">TestApplication</string>
<string name="action_settings">Settings</string>
<string name="action_search">Search</string>
<string name="icon"></string>
</resources>
Activity_Main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
android:background="#151415" >
<Button
android:id="#+id/button3"
android:layout_width="120dp"
android:layout_height="75dp"
android:layout_weight="0.335"
android:background="#666666"
android:text="Button" />
</LinearLayout>
Also i putted the font-awesm.ttf into assets/fonts ..
Output
"2131099652 Text"

I got solution
camerabtn.append("TEXT HERE");
Thank You All Of you for Solutions..

Related

Getting error in linear layout

I am new to Android. I am reading official documentation of Android about linear layout.
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="15dp"
android:paddingRight="15dp"
tools:context="com.example.hassan_microsoft.a2ndday18122017.MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:hint="#string/to"/>
At this line => android:hint="#string/to"
it is giving error and not working as i want it to be worked.Picture1
this preview (Picture1) should be the result but mine is giving out as this one as below (Picture2). Picture2 What can be the problem.? Thanks.
Try this make your EditText hight to android:layout_height="wrap_content"
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:hint="#string/to"
/>
And also
You need Create a new string resource value in value res/values/String.xml like below code
<string name="to">To</string>
You need to declare the value of #string/to in your strings.xml
Go to app -> res -> values -> strings.xml
Create a new string value called to with the string value, it should look like this::
Sample App
<string name="to">To</string>
A simpler alternative would be to just change your hint value to :
android:hint="To"

Not able to add buttons and text fields to my android app

Ok so I followed the Android Tutorials at the developer.android.com to build my first app. So to create a simple user interface I added a button and text field given in the tutorial. But when I run it on my phone, I don't see the buttons or text field.
package com.example.lookforbuttons;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv= new TextView(this);
tv.setText("Buttons");
setContentView(tv);
}
}
The .xml file where I describe the layout is this:
<?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"
android:orientation="horizontal">
<EditText android:id="#+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
and the strings.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Buttons</string>
<string name="edit_message">Enter a message</string>
<string name="button_send">Send</string>
<string name="action_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
</resources>
The target android version is 4.03 since I am testing it on 4.03 phone. When I run this I only "Buttons" printed and no button or text field. Thanks.
You call setContentView twice. When you do this, the second time is what you will see on the screen because it will overwrite whatever layout you called in the first call to setContentView(). So since you call
setContentView(tv);
last you only have the TextView. Remove that line and you should see your EditText and your Button.
In your code you are setting setContentview() twice. That means you are changing the layout which contains Button and TextView with second setContentview().
If you want to dynamically add new TextView to your layout. Remove the second setContentView() and assign an id to your LinearLayout in xml. Then find it in your Java code and say linearlayout.add(textview)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lv"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText android:id="#+id/edittext"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
Linearlayout lv=(Linearlayout) findViewById(R.id.lv);
lv.add(textview);

r.id id cannot be resolved

while i have programming an android program about voice recognizing i have a little problem.what is the r.id cannot be resolved i have try to change my xml files which includes res folder.it doesnt works.what can i do ?
my main.xml
<?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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
</LinearLayout>
Try cleaning your project (in Eclipse: Project->Clean...).
If that does not fix it delete your R.java file located under the gen folder. The R.java file should be regenerated for you.
I have done these thing to fix the problem you are describing, but your mileage may vary.
If somewhere in your class file you have a line like this:
TextView tv = (TextView) findViewById(R.id.tv1);
then R.id.tv1 must point to a TextView in your xml, which must first be given the id. So for example if you wanted to change the text in your TextView above you would have something like this to set the id in the xml:
<?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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
//Set your id here:
android:id="#+id/TEXTVIEW1"
/>
and then to change the text, in your class you'd have this:
TextView tv = (TextView) findViewById(R.id.TEXTVIEW1);
tv.setText("How are you");
Insert this to your xml file's view tags.
android:id="#+id/YOUR_VIEW_ID"

Loading animations with buttons in android

I have an activity in android which I set up a button under a SurfaceView. And the result looks like this:
And I'm satisfied with it except one thing, the writing on the button is astray and must be setup correctly.
For this I used animations like this:
takePhoto = (Button) findViewById(R.id.btnPhoto);
takePhoto.setText(t);
RotateAnimation ranim = (RotateAnimation)AnimationUtils.loadAnimation(this, R.anim.myanim);
ranim.setFillAfter(true);
takePhoto.setAnimation(ranim);
WHERE the res/anim/myanim looks like:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="-90"
android:pivotX="50%"
android:pivotY="50%"
android:duration="0" />
But the result is a little bit disappointing cause the whole looks like:
The text is ok, but the dimensions are reduced.
What I want is to keep the text correctly and the initial size.How could I do that???
It has nothing to do with the button's properties in the xml file cause I haven't changed them when loading the animation....Ideas?Thanks...
EDIT: xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
>
<SurfaceView android:layout_width="450dip"
android:layout_height="fill_parent" android:id="#+id/surface_camera" />
<RelativeLayout android:layout_width="fill_parent"
android:layout_toRightOf="#id/surface_camera"
android:layout_height="fill_parent"
>
<Button android:layout_width="680dip"
android:layout_height="680dip"
android:id="#+id/btnPhoto"
android:layout_alignParentBottom="true"
android:text="Take Photo"
android:layout_gravity="bottom|right" />
</RelativeLayout>
</RelativeLayout>
IMPORTANT:
In the cases described below...my activity is in `LANDSCAPE` mode and the position of the phone is portrait.Another issue is that when I turn my phone in landscape mode(and here I mean the position of the phone, cause the activity is still landscape) the button doesn't go at the bottom of the phone is stays there.No matter how I turn the phone the button is in the same position!!!!
You should read this
Make two layout folders like follows ...
In both of folders your layout file name should be same.
In layout-port folder your layout file should look like this ...
android:layout_toRightOf="#id/surface_camera"
replaced by ...
android:layout_Below="#id/surface_camera"
as follows ...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
>
<SurfaceView android:layout_width="450dip"
android:layout_height="fill_parent" android:id="#+id/surface_camera" />
<RelativeLayout android:layout_width="fill_parent"
android:layout_toBelow="#id/surface_camera"
android:layout_height="fill_parent"
>
<Button android:layout_width="680dip"
android:layout_height="680dip"
android:id="#+id/btnPhoto"
android:layout_alignParentBottom="true"
android:text="Take Photo"
android:layout_gravity="bottom|right" />
</RelativeLayout>
</RelativeLayout>
Even this will considered as bad practice but you can also handle this manually, try this ..
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
int orientation = getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_PORTRAIT) {
setContentView(R.layout.main1);
}
else {
setContentView(R.layout.main2);
}
}
Also If you are doing this way No need to make two layout folders, but needs two layout files main1 and main2 in same folder
Yet another option ...
In manifest ...
<activity android:name=".ActivityName" android:configChanges="keyboardHidden|orientation">
+
In your Activity ...
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
int orientation = newConfig.orientation;
if(orientation == Configuration.ORIENTATION_PORTRAIT) {
setContentView(R.layout.main2);
}
else {
setContentView(R.layout.main);
}
}
Try this XML instead:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="fill_parent">
<SurfaceView android:id="#+id/surface_camera"
android:layout_width="450dip"
android:layout_height="fill_parent" />
<FrameLayout android:layout_width="fill_parent"
android:layout_toRightOf="#id/surface_camera"
android:layout_height="fill_parent">
<Button android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView android:id="#+id/btnPhoto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Take Photo" />
</FrameLayout>
</RelativeLayout>
You will rotate the Text not the button.

How to create unfocussed,enabled edittextbox in android

i've created one searchEditBox and a button.Initially when the page loads.,the searchEditBox will be focussed with orange color mark automatically.when i use searchValue.setFocusable(false);.,its unfocussed but i couldnt able to type anything on that box(Box will be disabled).How could i recover this probs.?
java:
setContentView(R.layout.main);
edit=(EditText)findViewById(R.id.edit);
but=(Button)findViewById(R.id.but);
edit.setFocusable(false);
xml:
Hopefully this will solve your problem. Add the android:focusableInTouchMode="true" to your linearLayout that holds your EditText in your mail.xml file.
ie:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/linearLayout"
android:focusableInTouchMode="true">
This worked for me. Very simple solution.
comment your edit.setFocusable(false);
use searchValue.requestFocus() to set focus on EditText. It will work for you.
Check the following code.
Activity
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.admob);
// Lookup R.layout.main
EditText edit = (EditText) findViewById(R.id.edit);
Button but=(Button)findViewById(R.id.but);
// edit.setFocusable(false);
edit.requestFocus();
}
admob.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/linearLayout">
<EditText android:id="#+id/edit"
android:layout_width="250px"
android:layout_height="wrap_content"
/>
<Button android:id="#+id/but"
android:layout_width="80px"
android:layout_height="wrap_content"
android:text="click"/>
</LinearLayout>
Donot forget to vote if my response is helpful for you.
Thanks
Deepak

Categories

Resources