繁体   English   中英

Android | 膨胀按钮不起作用

[英]Android | Inflated Buttons don't work

我用以下代码为我的布局充气:

   FrameLayout frameLayout = findViewById(R.id.activity_frame);

    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View activityView5 = layoutInflater.inflate(activity_start_home, null, false);

        frameLayout.addView(activityView5);

我膨胀的XML布局如下所示:

    <?xml version="1.0" encoding="utf-8"?>
 <android.support.design.widget.CoordinatorLayout    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.musictrainer.music_trainer.StartHome">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/background"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_start_home" />

  </android.support.design.widget.CoordinatorLayout>

此布局中包含的“内容”如下所示:

<?xml version="1.0" encoding="utf-8"?>
 <android.support.constraint.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"
android:background="@color/background"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.musictrainer.music_trainer.StartHome"
tools:layout_editor_absoluteY="81dp"
tools:showIn="@layout/activity_start_home">

<Button
    android:id="@+id/inton_but"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="92dp"
    android:background="@color/buttons"
    android:text="Intonation"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/tuner_but"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="64dp"
    android:background="@color/buttons"
    android:text="Tuner"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/inton_but" />
  </android.support.constraint.ConstraintLayout>

因此,当我为布局充气时,它会显示布局,但是按钮不起作用。 我也必须给按钮充气吗? 我是否需要充实内容?

如果您要根据导航项更改布局,建议您使用一个片段

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM