Showing posts with label Andoid Button. Show all posts
Showing posts with label Andoid Button. Show all posts

Friday, March 23, 2018

Floating Action Button Ekleme

Selam Arkadaşlar,

Android Studio 'da proje geliştirirken bazen Image View , Text View veya ViewPager'lar üzerine buton eklemek isteriz. Bunu yapabilmek için ihtiyacımız olan ise Floating Action Button😉 Ben Text View üzerine Floating Action Button Ekleme işlemini örnekleyeceğim.


Öncelikle Gradle kısmına aşağıdaki kodları yazın ve Sync Now ' a basın.

1
2
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'

Daha sonra .xml dosyasının gerekli kısmına aşağıdaki kodda gerekli kısımları alın:)

 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
 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/favplus"
        app:backgroundTint="#FFFFFF"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="24dp"
        android:layout_marginStart="24dp"
        android:clickable="true"
        app:fabSize="mini"/>

    <TextView
        android:id="@+id/text1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/bg3"
        android:padding="10dp"
        android:fontFamily="sans-serif"
        android:gravity="center"
        android:textAlignment="center"
        android:textColor="#000000"
        android:textStyle="italic" />
</RelativeLayout>

Tuesday, January 23, 2018

Android Studio Bottona Tıklama

Android Studio'da geliştirdiğimiz  uygulamalarda, butona bastığımızda bir olayın gerçekleşmesini istiyorsak setOnclickListener() özeliğini kullanılırız. setOnclickListener() özelliğini, buttona bastığımızda ekranda görünen text'in rengni değiştiren bir uygulama ile örneklemeye çalışacağım.

activity_main.xml Sayfası aşağıdaki gibi olacaktır.

 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
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.hande.umut.buttontiklama.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Hello World!"
            android:textSize="100sp"
            android:gravity="center"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Button
            android:id="@+id/renkDegistir"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Renk Değiştir" />
    </LinearLayout>

</android.support.constraint.ConstraintLayout>

java kodlarıda aşağıda verildiği gibidir:)
 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
package com.hande.umut.buttontiklama;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    Button renkDegistir;
    TextView textView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        renkDegistir= (Button) findViewById(R.id.renkDegistir);
        textView= (TextView) findViewById(R.id.textView);

        renkDegistir.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                textView.setTextColor(Color.BLUE);
            }
        });
    }
}

Butona Tıklamadan Önceki Ekran Görüntüsü

Butona Tıkladıktan Sonraki Ekran Görüntüsü