MainActivity.java
package com.sam.web.share;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater=getMenuInflater();
menuInflater.inflate(R.menu.menu_item,menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId()==R.id.shareId){
}
else if(item.getItemId()==R.id.feedbackId){
Intent intent=new Intent(getApplicationContext(),FeedbackActivity.class);
startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
}
activity_main.xml
<?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"
tools:context="com.sam.web.share.MainActivity">
</LinearLayout>
FeedbackActivity.java
package com.sam.web.share;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class FeedbackActivity extends AppCompatActivity implements View.OnClickListener {
private Button sendButton, clearButton;
private EditText nameEditText, messageEditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feedback);
sendButton=(Button) findViewById(R.id.sendButtonId);
clearButton=(Button) findViewById(R.id.clearButtonId);
nameEditText=(EditText) findViewById(R.id.nameEditTextId);
messageEditText=(EditText) findViewById(R.id.messageEditTextId);
sendButton.setOnClickListener(this);
clearButton.setOnClickListener(this);
}
@Override
public void onClick(View view) {
try {
String name=nameEditText.getText().toString();
String message=messageEditText.getText().toString();
if(view.getId()==R.id.sendButtonId){
Intent intent=new Intent(Intent.ACTION_SEND);
intent.setType("text/email");
intent.putExtra(Intent.EXTRA_EMAIL,new String[] {"sam1206@gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT,"Feedback from app");
intent.putExtra(Intent.EXTRA_TEXT,"Name :"+name+" Message: "+message);
startActivity(Intent.createChooser(intent,"Feedback with"));
}
else if(view.getId()==R.id.clearButtonId){
nameEditText.setText("");
messageEditText.setText("");
}
}catch (Exception e){
Toast.makeText(getApplicationContext(),"Exception "+e,Toast.LENGTH_SHORT).show();
}
}
}
activity_feedback.xml
<?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:padding="10dp"
android:background="#22ffff"
android:orientation="vertical"
android:weightSum="4"
tools:context="com.sam.web.share.FeedbackActivity">
<LinearLayout
android:layout_weight="0.5"
android:layout_width="match_parent"
android:layout_height="0dp">
<EditText
android:textStyle="bold"
android:textSize="17sp"
android:id="@+id/nameEditTextId"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"
android:hint="Enter your name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_weight="1.5"
android:layout_width="match_parent"
android:layout_height="0dp">
<EditText
android:textStyle="bold"
android:textSize="17sp"
android:id="@+id/messageEditTextId"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"
android:hint="Enter your Message"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:gravity="center"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
<Button
style="@style/Base.TextAppearance.AppCompat.Widget.Button"
android:textSize="17sp"
android:textStyle="bold"
android:text="send"
android:id="@+id/sendButtonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
style="@style/Base.TextAppearance.AppCompat.Widget.Button"
android:textSize="17sp"
android:textStyle="bold"
android:text="clear"
android:id="@+id/clearButtonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
meneu_item.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/feedbackId"
android:title="Feedback"
app:showAsAction="never" />
<item
android:id="@+id/shareId"
android:title="Share"
app:showAsAction="never" />
</menu>