Ben sallamak üzerinde gösterileri rastgele renk olduğu bir uygulamayı yaptık. Şimdi ben biraz bir oyun bunu telafi etmeye çalıştı. Ama şimdi düğmeleri işlemek kuramıyorum. Benim ana fikri ilk olarak gevşek Burada kodumu bulabilirsiniz renk eşleme sonra aksi kazanmak varsa sallamak sonra ardından düğmesine seçmek için kullanıcı ihtiyaç vardır. Bununla Can herkes yardım etmek beni? Bu nasıl benim app görünüyor olduğunu
İşte benim .XML aşağıdaki gibidir:
<?xml version=1.0 encoding=utf-8?>
<androidx.constraintlayout.widget.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>
<Button
android:id=@+id/t21
android:layout_width=0dp
android:layout_height=84dp
android:layout_marginStart=32dp
android:layout_marginLeft=32dp
android:layout_marginEnd=32dp
android:layout_marginRight=32dp
android:layout_marginBottom=16dp
android:background=#59C4C5
android:text=Win or Loose
app:layout_constraintBottom_toTopOf=@+id/tableLayout
app:layout_constraintEnd_toEndOf=parent
app:layout_constraintHorizontal_bias=1.0
app:layout_constraintStart_toStartOf=parent
app:layout_constraintTop_toTopOf=parent
app:layout_constraintVertical_bias=1.0 />
<TableLayout
android:id=@+id/tableLayout
android:layout_width=354dp
android:layout_height=237dp
android:layout_marginStart=32dp
android:layout_marginLeft=32dp
android:layout_marginEnd=32dp
android:layout_marginRight=32dp
android:layout_marginBottom=16dp
app:layout_constraintBottom_toTopOf=@+id/t
app:layout_constraintEnd_toEndOf=parent
app:layout_constraintStart_toStartOf=parent>
<TableRow
android:layout_width=match_parent
android:layout_height=match_parent>
<Button
android:id=@+id/t1
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#fed766
android:minWidth=88dp
android:text= />
<Button
android:id=@+id/t2
android:layout_width=wrap_content
android:layout_height=wrap_content
android:minWidth=88dp
android:text=
android:background=#eec9d2
/>
<Button
android:id=@+id/t3
android:layout_width=wrap_content
android:layout_height=wrap_content
android:minWidth=88dp
android:text=
android:background=#f07d38
/>
<Button
android:id=@+id/t4
android:layout_width=wrap_content
android:layout_height=wrap_content
android:minWidth=88dp
android:text=
android:background=#c7243a
/>
</TableRow>
<TableRow
android:layout_width=match_parent
android:layout_height=match_parent>
<Button
android:id=@+id/t5
android:layout_width=wrap_content
android:layout_height=wrap_content
android:text=
android:background=#f485c7
/>
<Button
android:id=@+id/t6
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#ff1f5d4f
android:text= />
<Button
android:id=@+id/t7
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#c6cc56a9
android:text= />
<Button
android:id=@+id/t8
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#f3227588
android:text= />
</TableRow>
<TableRow
android:layout_width=match_parent
android:layout_height=match_parent>
<Button
android:id=@+id/t9
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#f2684ab4
android:text= />
<Button
android:id=@+id/t10
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#d2e7ff
android:text= />
<Button
android:id=@+id/t11
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#ff6f69
android:text= />
<Button
android:id=@+id/t12
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#bed905
android:text= />
</TableRow>
<TableRow
android:layout_width=match_parent
android:layout_height=match_parent>
<Button
android:id=@+id/t13
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#e43afee1
android:text= />
<Button
android:id=@+id/t14
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#bf30b02f
android:text= />
<Button
android:id=@+id/t15
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#a8e6cf
android:text= />
<Button
android:id=@+id/t16
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#d2d4dc
android:text= />
</TableRow>
<TableRow
android:layout_width=match_parent
android:layout_height=match_parent>
<Button
android:id=@+id/t17
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#ea9ed0a6
android:text= />
<Button
android:id=@+id/t18
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#d9ad0495
android:text= />
<Button
android:id=@+id/t19
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#fff4e6
android:text= />
<Button
android:id=@+id/t20
android:layout_width=wrap_content
android:layout_height=wrap_content
android:background=#be9b7b
android:text= />
</TableRow>
</TableLayout>
<Button
android:id=@+id/t
android:layout_width=0dp
android:layout_height=84dp
android:layout_marginStart=32dp
android:layout_marginLeft=32dp
android:layout_marginEnd=32dp
android:layout_marginRight=32dp
android:text=Choose one of the above color
android:background=#8b9dc3
app:layout_constraintBottom_toBottomOf=parent
app:layout_constraintEnd_toEndOf=parent
app:layout_constraintStart_toStartOf=parent />
</androidx.constraintlayout.widget.ConstraintLayout>
İşte benim .java aşağıdaki gibidir:
package com.example.android.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.squareup.seismic.ShakeDetector;
import java.util.Random;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity implements ShakeDetector.Listener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
ShakeDetector shakeDetector = new ShakeDetector(this);
shakeDetector.start(sensorManager);
}
@Override
public void hearShake() {
Random rnd = new Random();
final TextView textView = findViewById(R.id.t);
int color = Color.argb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
textView.setText(Random color value is +Integer.toHexString(color)+\n and you choose +color);
findViewById(android.R.id.content).setBackgroundColor(color);
}
}
> Build.Gradle (Module.app) - - Ve burada Gradle komut dosyaları markasını sahip olduğu bir uygulamasıdır>
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.squareup:seismic:1.0.2' ///only this line is added.
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}