java - 安卓 |充气按钮不起作用

标签 java android android-layout

I inflate my layout with this code:

   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);

The XML-Layout I inflate looks like this:

    <?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>

The included "content" from this layout looks like this:

<?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>

因此,当我膨胀布局时,它会显示布局,但按钮不起作用。我也必须给按钮充气吗?我必须夸大内容吗?

最佳答案

如果您要根据导航项更改布局,我建议您使用 fragment

关于java - 安卓 |充气按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50062608/

相关文章:

Android - 当设备屏幕为空白时不接收 Wi-Fi 连接更改 Intent

android - 我的布局适用于一种屏幕尺寸,如何使其适用于 Android Studio 3.4.2 中的所有屏幕尺寸

java - 序列化 Collat​​or 实例

java - 使用中位数 3 的快速排序中的逻辑错误

java - 为什么我的自定义微调器被禁用/无响应?

java - 找不到适合 jdbc :mysql://localhost:3306/test 的驱动程序

Android NDK,找不到依赖库

java - 按钮的文本循环遍历字符串数组

android - 如何在android中使grid-view水平滚动

java - 多次调用 onFocusChange 导致 "hasFocus"变量不可用