Herkese Merhaba, Android ile ilgilenmeye tekrar başlayınca dedim bloga da yazı atmamazlık yapmayayım. Bu 3 ayda güzel yazılar eklemeye çalışacağım. Bir kaç hazır proje bile anlatmayı hedefliyorum. İlk proje paylaş butonu.
Activity_main.xml kodları :
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<RelativeLayout xmlns:android="https://schemas.android.com/apk/res/android" xmlns:tools="https://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:id="@+id/btnShare" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/lblContent" android:layout_marginTop="50dp" android:text="Paylaş" /> <EditText android:id="@+id/txtContent" android:layout_width="100dp" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:layout_toRightOf="@+id/lblContent" android:ems="10" > <requestFocus /> </EditText> <TextView android:id="@+id/lblContent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Paylaşılacak yazı" /> </RelativeLayout> Basit bir editText ile tanımlanmış yazıda textView içine girilen veri alınarak bir buton yardımıyla paylaşabiliyoruz. MainActivity.java dosyasının kodları |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
package googleyardim.example.info.paylas; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btnShare = (Button) findViewById(R.id.btnShare); final EditText txtContent = (EditText) findViewById(R.id.txtContent); btnShare.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // EditText'in içindeki yazıyı alır. String message = txtContent.getText().toString(); shareMyMessage(message); } }); } protected void shareMyMessage(String _message) { // TODO Auto-generated method stub Intent share = new Intent(Intent.ACTION_SEND); share.setType("text/plain"); share.putExtra(Intent.EXTRA_TEXT, _message); startActivity(Intent.createChooser(share, "Gönderiyi paylaş !! ")); } } Son olarak görselimiz ise <a href="https://8tz254.cdnnest.com/20220303061423im_/https://umiitkose.com/wp-content/uploads/2015/06/2015-06-30_01h04_04.png"><img class="alignnone size-large wp-image-1000" src="https://kisw0c4b.cdnnest.com/20220303061423im_/https://umiitkose.com/wp-content/uploads/2015/06/2015-06-30_01h04_04-1024x294.png" alt="2015-06-30_01h04_04" width="640" height="184" /></a> <a href="https://az9t2v.cdnnest.com/20220303061423im_/https://umiitkose.com/wp-content/uploads/2015/06/2015-06-30_01h08_21.png"><img class="alignnone size-large wp-image-1001" src="https://6nd4gxg7.cdnnest.com/20220303061423im_/https://umiitkose.com/wp-content/uploads/2015/06/2015-06-30_01h08_21-600x1024.png" alt="2015-06-30_01h08_21" width="600" height="1024" /> D</a>iğer Yazılarda Görüşmek dileğiyle |
1 thought on “Android Ders 28 – Paylaş Butonu Yapımı”
Mısdaa
(15 Eylül 2016 - 18:43)Bu kodlar yazı paylaşımı için sanırım. Peki resim paylaşmak için kod var mı? Biraz araştırdım ama bulamadım.