how to link the image button to a facebook page in android - java

i am new to android ....
i have designed a view where i have created 4 image buttons
in that one has to go to facebook url
second has to go twitter url
third has to go to youtube url etc like that
fourth to linkedin
but i dont know how to configure the button to send a url and the page must inside the same design view shown below
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/apple" >
<Button
android:id="#+id/main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#2C3539"
android:gravity="center"
android:text="#string/apple"
android:textColor="#FFFFFF"
android:textSize="22sp" />
<Button
android:id="#+id/video"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/music"
android:background="#2C3539"
android:text="#string/video"
android:textColor="#FFFFFF"
android:textColorHint="#color/black"
android:textSize="20sp" />
<Button
android:id="#+id/music"
android:layout_width="160dp"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#2C3539"
android:text="#string/music"
android:textColor="#FFFFFF"
android:textColorHint="#color/black"
android:textSize="20sp" />
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/main"
android:layout_marginLeft="41dp"
android:layout_marginTop="72dp" >
</TableLayout>
<ImageButton
android:id="#+id/twitter1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/facebook1"
android:src="#drawable/twitter" />
<ImageButton
android:id="#+id/facebook1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/main"
android:src="#drawable/facebook" />
<ImageButton
android:id="#+id/youtube1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/twitter1"
android:src="#drawable/youtube" />
<ImageButton
android:id="#+id/instagram1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/youtube1"
android:src="#drawable/instagram_icon" /></RelativeLayout>
the above code looks like this if i click on facebook image then it has to populate this link
https://www.facebook.com/apple.fruit
And link has to populate onto body (shown in image)
can anyone write the backend code how to use the button
i have created one java file
package com.lay.background;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
public class AppleActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.apple);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.second, menu);
return true;
} }
Can anyone please resolve the code if any queries please comment

for each button you can pass the intent with specific URL like this
Intent browserIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.facebook.com/apple.fruit"));
startActivity(browserIntent);
For example if your button is facebookButton then use it in your Activity like this:
ImageButton facebookButton = (ImageButton)findViewById(R.id.facebook1);
facebookButton.setOnClickListener(new View.onClickListener()
{
public void onClick(View arg0)
{
Intent browserIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.facebook.com/apple.fruit"));
startActivity(browserIntent);
}
});
other way would be loading your URL into a WebView.
myWebView.loadUrl(http://"+tempUrl);
As for the missing "http://" I'd just do something like this:
if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;
Adding WebView in xml layout file:
<WebView android:id="#+id/webview"
android:layout_width="fill_parent" android:layout_height="50dip"/>
Add the WebView content with your Url in MainActivity :
// Enable javascript for the view
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(this, description, Toast.LENGTH_SHORT).show();
}
});
mWebview .loadUrl("http://www.facebook.com/apple.fruit");

try this.
first, add Webview in you layout file that visible is gone.
if button is clicking, set webview visible is visible, and using webview is connect you want connect url.

Related

onClick method not working in android studio

I made a side navigation drawer and it works fine but whenever I click any option in navigation drawer nothing happens.It's like it is not taking any input. Onclicking any option I want to redirect user to a new activity but unfortunately it doesn't happens.
XML code is as follows
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:clickable="true"
android:onClick="ClickTournament_info"
android:focusable="true">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Tournament Info"
android:padding="12dp"
android:layout_marginStart="16dp"/>
<ImageView
android:layout_marginTop="-10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="48dp"
android:src="#drawable/tournament_info"/>
</LinearLayout>
Java code is as follows
public void ClickTournament_info(View view){
redirectActivity(this,TournamentInfo.class);
}
public static void redirectActivity(Activity activity,Class aClass) {
//Initialize intent
Intent intent = new Intent(activity,aClass);
//set flag
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//start activity
activity.startActivity(intent);
}
I think you need to use the onNavigationItemSelected method when you want to handle click events on the navigation drawer.
Learn more: https://developer.android.com/reference/com/google/android/material/navigation/NavigationView.OnNavigationItemSelectedListener#onNavigationItemSelected(android.view.MenuItem)
Firstly, try to always create an Onclicklistener instead of adding an onclick attribute in xml.
In your xml, add an ID attribute to your linear layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearlayout"
android:orientation="horizontal"
android:gravity="center_vertical"
android:clickable="true"
android:onClick="ClickTournament_info"
android:focusable="true">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Tournament Info"
android:padding="12dp"
android:layout_marginStart="16dp"/>
<ImageView
android:layout_marginTop="-10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="48dp"
android:src="#drawable/tournament_info"/>
</LinearLayout>
Now in your classfile inside the Oncreate Method,
LinearLayout LinearLayout = (LinearLayout )findViewById(R.id.linearlayout);
LinearLayout.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
redirectActivity(this,TournamentInfo.class);
}
});
You already have an onClick method. start navigating from that method only.
Try like this,

How to pass information between activities using rating bar

Ok, so im pretty new to android and the whole app making but im just doing like a generic app rating thing just for practice. Here are the details I have just 2 generic pictures on the main activity with a rate button beside each and a text view below them both so when you click the rate button it takes you to the second activity which has the rating bar. This is my problem in the view with the rating bar I just have the display for the rating as a toast but i want to be able to take that rating and display it inside the textview in my main activity and its posing more of a problem than i thought it was going to so im looking for a bit of help
this is the code for my main activity
package com.example.brent.appmanagement;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ratingapp1();
ratingapp2();
getrating();
}
private void getrating(){
}
private void ratingapp1(){
Button rateapp1 = findViewById(R.id.rateapp1);
rateapp1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this, firstapp.class));
}
});
}
private void ratingapp2(){
Button rateapp2 = findViewById(R.id.rateapp2);
rateapp2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this, secondapp.class));
}
});
}
}
and this is the code for the activity with the rating bar
public class firstapp extends AppCompatActivity {
public RatingBar ratingBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_firstapp);
ratingBar = findViewById(R.id.ratingBar);
return1();
}
public void rateMe(View view){
Toast.makeText(getApplicationContext(),
String.valueOf(ratingBar.getRating()),
Toast.LENGTH_LONG).show();
}
private void return1(){
Button returntomain1 = findViewById(R.id.returntomain1);
returntomain1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(firstapp.this, MainActivity.class));
}
});
}
}
also I have the XML which i dont know if you need to see but here it is
main activity
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
tools:context="com.example.brent.appmanagement.MainActivity">
<Button
android:id="#+id/rateapp1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="96dp"
android:layout_marginTop="124dp"
android:text="Rate"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/rateapp2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="176dp"
android:layout_marginEnd="96dp"
android:text="Rate"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="96dp"
android:layout_marginTop="112dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#mipmap/ic_launcher" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="164dp"
android:layout_marginStart="96dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#mipmap/ic_launcher" />
<TextView
android:id="#+id/savedrating1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="96dp"
android:layout_marginTop="12dp"
android:text=""
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView3" />
<TextView
android:id="#+id/savedrating2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="96dp"
android:layout_marginTop="12dp"
android:text=""
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView4" />
</android.support.constraint.ConstraintLayout>
and the second activity
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
tools:context="com.example.brent.appmanagement.firstapp">
<Button
android:id="#+id/returntomain1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:text="Return to main menu"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/rate_me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Rate Me"
android:textSize="18dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RatingBar
android:id="#+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rate_me"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:numStars="5"
android:stepSize="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/rate_me" />
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ratingBar"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:onClick="rateMe"
android:text="Submit"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/ratingBar" />
</android.support.constraint.ConstraintLayout>
I would like to have the rating from the rating bar inside firstactivity be displayed in the textview savedrating1 inside my main activity
thanks all in advance for the help
for primitive values you can stuff them inside the intent using key value pairsIntent intent =new Intent(); String myValue="something";intent.putExtra("keyMyValue",myValue);startActivity(intent); for passing custom objects use parcelable and stuff the parcelable into the intent as above or here

how to connect button with next screen on android studio

I am building this application on android studio and i am trying to link my button with next activity which is login screen. before i had it working with register screen but then i messed up with code now it just doesn't work when i run the application and click on register button my app crashes and shuts down and login button doesn't even do anything.
below is the code for main page activity and login page activity
first i will paste frontpage activity code where the button is, then its java class, then i will paste loginpage activity and then its java class.
can someone pls advice me how to call the login activity from the login button on the front page.
thank you so much in advance
frontpage activity
<?xml version="1.0" encoding="utf-8"?>
<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=".Login">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:background="#drawable/bg3"
android:gravity="center|top">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Easy Booking"
android:id="#+id/textView"
android:textSize="33dp"
android:gravity="center"
android:textColor="#0c0c0c"
/>
<Button
android:layout_width="98dp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Login"
android:id="#+id/btLogin"
android:onClick="bLogin"
android:background="#null"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="108dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Register"
android:id="#+id/btRegister"
android:onClick="bRegister"
android:background="#null"
android:layout_gravity="center_horizontal" />
</LinearLayout>
now its java class
public class Frontpage extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frontpage);
//OnclickButtonListener();
}
public void bLogin(View view) {
}
public void onButtonClick(View v){
if (v.getId() == R.id.btRegister) {
Intent i = new Intent(new Intent(Frontpage.this, Register.class));
startActivity(i);
}
}
/**
public void OnclickButtonListener(){
button = (Button)findViewById(R.id.bRegister);
button.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("/Users/umairfarooq/AndroidStudioProjects/Easybooking/app/src/main/res/layo ut/activity_register");
startActivity(intent);
}
}
);
} /**#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main_activity_login, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
*/}
below is the login activity
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#635b5b"
android:orientation="vertical"
android:layout_width="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Form"
android:textAppearance="?android:textAppearanceLarge"
android:textStyle="bold"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
/>
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="Email"
android:id="#+id/etUsername"
android:layout_gravity="center_horizontal"
android:layout_marginTop="70dp"
/>
<EditText
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="Password"
android:id="#+id/etPassword"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:inputType="textPassword"
/>
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Login"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:onClick="userLogin"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register Now"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:onClick="userReg"
/>
</LinearLayout>
and now login java class
package com.example.umairfarooq.easybooking;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
public class Login extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
public void buttonOnClick (View v){
}
}
The problem is that your activities don't contain the methods that you've set for your buttons' android:onClick attribute.
For the layout that the Frontpage activity is using, you can either change btRegister button's android:onClick attribute to android:onClick="onButtonClick" or create a public void bRegister(View v){...} method in that activity.
For the Login activity, the layout has two buttons with their android:onClick attribute set to userReg and userLogin, you can either create those methods in the activity or change both of those attributes values to buttonOnClick.
when i run the application and click on register button my app crashes
and shuts down
It is because this button:
<Button
android:layout_width="108dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Register"
android:id="#+id/btRegister"
android:onClick="bRegister"
android:background="#null"
android:layout_gravity="center_horizontal" />
in your frontpage activity needs a method with signature public void bRegister(View view) in your FrontPage.java class. As you do not have this method, it crashes.
login button doesn't even do anything
The reason is, this button
<Button
android:layout_width="98dp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Login"
android:id="#+id/btLogin"
android:onClick="bLogin"
android:background="#null"
android:layout_gravity="center_horizontal" />
in your frontpage activity needs a method called public void bLogin(View view) in your Frontpage.java class. Though the method is present, you do not have any code in it, hence it does not do anything.
You need to add proper code in bLogin method so that your login button starts functioning, and even before that add a bRegister method so that your register button starts working.
Hope this helps you.

Moving buttons with animation and changing their position afterwards

I am learning Java and Android SDK. I want to create a simple application that is swapping 2 buttons so the left one is moving to the place of right one and v.v. with simple animation. I have tried the ObjectAnimator because I have read that it is moving the views objects permanently. But it's not :-( The objects stays there I mean the left one on the right and v.v. but their getLeft(), getTop() values are the same, and after next animations starts the objects are returning to the start position immediately. I have read that the ObjectAnimator needs some additional function to work properly but in the documentation there is no example :-( I have tried to add the setTranslationX function but it hasn't worked. Could somebody provide me with some simple example of how to do this?
http://developer.android.com/guide/topics/graphics/prop-animation.html#object-animator
"The object property that you are animating must have a setter function (in camel case) in the form of set(). Because the ObjectAnimator automatically updates the property during animation, it must be able to access the property with this setter method. For example, if the property name is foo, you need to have a setFoo() method. If this setter method does not exist, you have three options:
Add the setter method to the class if you have the rights to do so.
Use a wrapper class that you have rights to change and have that wrapper receive the value with a valid setter method and forward it to the original object.
Use ValueAnimator instead."
Thanks in advance.
try this code:
public class ActivityStartup extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("hello");
setContentView(R.layout.main);
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.SLIDING_WINDOW);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setBehindOffset(100);
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
View view = G.layoutInflater.inflate(R.layout.menu, null);
view.findViewById(R.id.layout_crop).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(G.context, "Crop Clicked", Toast.LENGTH_SHORT).show();
}
});
view.findViewById(R.id.img_logo).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://example.com"));
startActivity(browserIntent);
}
});
menu.setMenu(view);
}
}
public class G extends Application {
public static LayoutInflater layoutInflater;
public static Context context;
#Override
public void onCreate() {
super.onCreate();
layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
context = getApplicationContext();
}
}
main.xml is:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
menu.xml is:
<ImageView
android:id="#+id/img_logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="8dip"
android:scaleType="centerInside"
android:src="#drawable/hlogo" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#00ff00"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:id="#+id/layout_crop"
android:layout_width="match_parent"
android:layout_height="48dip"
android:gravity="center_vertical" >
<ImageView
android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dip"
android:scaleType="centerInside"
android:src="#android:drawable/ic_menu_crop" />
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Crop"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_day"
android:layout_width="match_parent"
android:layout_height="48dip"
android:gravity="center_vertical" >
<ImageView
android:id="#+id/ImageView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dip"
android:scaleType="centerInside"
android:src="#android:drawable/ic_menu_day" />
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_delete"
android:layout_width="match_parent"
android:layout_height="48dip"
android:gravity="center_vertical" >
<ImageView
android:id="#+id/ImageView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dip"
android:scaleType="centerInside"
android:src="#android:drawable/ic_menu_delete" />
<TextView
android:id="#+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete"
android:textColor="#000000" />
</LinearLayout>

font size will be increase on whole app textview when click image

I have to develop one android application.
Here i have to click one image means automatically increase the font size on whole app textview.how can i develop these like iphone BBC news app . please give me some idea ???
EDIT:
please see here.here see the 2nd image bottom -A +A image is there...that purpose is have to click that image means automatically increase and decrese the whole app textview fontsize.
how can we ll do in android app ???
Use imageview and implement onclicklisetner
XML
<TextView
android:id="#+id/firsttv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="serif"
android:gravity="center"
android:layout_marginBottom="20dip"
android:layout_marginTop="20dip"
android:text="#string/prompt" />
<ImageButton
android:id="#+id/imagebtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:contentDescription="#string/description"
android:onClick="onclickbtn"
/>
Java
Register:
TextView tv;
tv=(TextView)findViewById(R.id.firsttv);
Onclick
public void onclickbtn(View v){
tv.setTextSize(20);
}
Here is implemented version of your query:
Java Code:
package com.anurag.increasefont;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView tv;Button b1,b2;int count=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView)findViewById(R.id.tv1);
b1=(Button)findViewById(R.id.b1);
b2=(Button)findViewById(R.id.b2);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void increase(View inc){
count++;
if(count==1){tv.setTextSize(20); }
else if(count==2){tv.setTextSize(30);}
else if (count>=3) {count=3;tv.setTextSize(40);}
}
public void decrease(View dec){
count--;
if(count<=0){tv.setTextSize(12);count=0;}
if(count==1){tv.setTextSize(20);}
else if(count==2){tv.setTextSize(30);}
else if (count==3) {tv.setTextSize(40);}
}
}
XML Code:
<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"
android:padding="2dp"
tools:context=".MainActivity" >
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="This is sample text, i will increase and decrease the font size when user clicks on A+ and A_ buttons provided below. I can also use imageview or image button instead of Buttons to perform the same" />
<Button
android:id="#+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/textView1"
android:onClick="decrease"
android:text="Decrease" />
<Button
android:id="#+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="increase"
android:text="Increase" />
</RelativeLayout>

Categories

Resources