Android Studio - Image Button compiling Fehler

  • Antworten:8
milos.buttler
  • Forum-Beiträge: 11

16.06.2019, 15:19:01 via Website

Guten Tag,

ich möchte gerne einen ImageButton in meine App einbauen, jedoch sorgt diese für Probleme. Wenn ich dem Hintergrund meines Buttons ein Bild hinzufüge und ich die App dann starten möchte, sorgt dieser dafür, dass meine Verknüpfungen mit meinen Buttons und TextViews per findViewById(R.id.) nicht mehr vorhanden sind ("R" im Code rot).

In "Build" unter "Java compiler" wird mir " error: failed linking file resources." angezeigt.

Ich freue mich über jede Hilfe

Vielen Dank im Voraus

MfG
Milos

— geändert am 16.06.2019, 16:19:34 durch Moderator

Kommentieren
Jokel
  • Forum-Beiträge: 1.527

16.06.2019, 15:24:54 via Website

Hallo da wird was in deiner Layout Datei falsch sein.
Poste die mal Bitte.

PS. wo in welchen Odner ist die Image Datei (Bild)
wie bindest du das ein? dazu bitte Layout und wie du es in Java einfügst.

— geändert am 16.06.2019, 15:31:38

Hilfreich?
Kommentieren
milos.buttler
  • Forum-Beiträge: 11

16.06.2019, 15:28:34 via Website

Guten Mittag,

vielen Dank für die schnelle Antwort. Im Folgenden die Layout Datei:

<?xml version="1.0" encoding="utf-8"?>

android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
    android:id="@+id/btn_start"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="64dp"
    android:layout_marginBottom="116dp"
    android:background="@color/colorPrimaryDark"
    android:onClick="start"
    android:text="Start"
    android:textAlignment="center"
    android:textColor="@android:color/background_dark"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

<TextView
    android:id="@+id/tv_anz"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="72dp"
    android:layout_marginEnd="8dp"
    android:text="Schätze 8 Sekunden!

Je näher du kommst, desto
mehr Punkte gibt es!"
android:textAlignment="center"
android:textColor="@android:color/background_dark"
android:textSize="24sp"
android:textStyle="bold"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/btn_stop"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="116dp"
    android:background="@color/colorPrimaryDark"
    android:onClick="pause"
    android:text="Stop"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.546"
    app:layout_constraintStart_toEndOf="@+id/btn_start" />

<TextView
    android:id="@+id/tv_timer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:text="00:00:00"
    android:textColor="@color/colorPrimaryDark"
    android:textSize="80dp"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.502"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/btn_next"
    android:layout_width="50"
    android:layout_height="50"
    android:layout_marginEnd="13dp"
    android:layout_marginBottom="8dp"
    android:background="?android:attr/homeAsUpIndicator"
    android:onClick="next"
    android:rotation="180"
    android:textAllCaps="true"
    android:textStyle="bold"
    android:visibility="invisible"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent" />

Vielen Dank im Voraus

MfG
Milos

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.527

16.06.2019, 15:41:32 via Website

android:layout_width="50"
android:layout_height="50"

gib hier mal sinnvolle werte an "50dp"

Hilfreich?
Kommentieren
milos.buttler
  • Forum-Beiträge: 11

16.06.2019, 15:48:34 via Website

Vielen Dank, das war's schon.

MfG
Milos

Hilfreich?
Kommentieren
milos.buttler
  • Forum-Beiträge: 11

16.06.2019, 17:25:27 via Website

Guten Tag,

ich hätte noch eine Frage: wie kann ich bestimmen, welche activity zuerst gestartet wird? Die MainActivity wir nämlich immer zuerst gestartet, aber ich möchte gerne das meine menue.java zuerst gestartet wird, da diese erst die MainActivity per Button öffnen soll.

Vielen Dank im Voraus

MfG
Milos

Hilfreich?
Kommentieren
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

16.06.2019, 17:47:08 via Website

Das kannst du auch über die Manifest festlegen.

Das Activity XML Tag was gestartet weren soll, braucht halt den passenden IntentFilter:

<intent-filter>
        <action android:name=
          "android.intent.action.MAIN" />
        <category android:name=
          "android.intent.category.LAUNCHER" />
      </intent-filter>

LG Pascal //It's not a bug, it's a feature. :) ;)

Hilfreich?
Kommentieren
milos.buttler
  • Forum-Beiträge: 11

16.06.2019, 18:02:31 via Website

Vielen Dank für die schnelle Antwort.

Muss ich das einfach in die .xml Datei einfügen, die als erstes gestartet werden soll und mehr nicht oder wie funktioniert das genau?

Vielen Dank im Voraus

MfG
Milos

Hilfreich?
Kommentieren
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

16.06.2019, 18:09:53 via Website

Du musst das in der Mainfest bei der Activity eintragen die gestartet werden soll:

https://stackoverflow.com/a/6467817

LG Pascal //It's not a bug, it's a feature. :) ;)

Hilfreich?
Kommentieren