为什么工具栏覆盖了另一个 activity 的片段?
Why Toolbar is Overriding another activity's fragment?
Im not added toolbar in this fragment but it is overriding from Recyclerview's xml file
Im added toolbar in this specific recyclerview's xml file
清单文件
<?xml version='1.0' encoding='utf-8'?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sanskrit.mysearcher">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:resizeableActivity="false">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DisplayContactActivity">
</activity>
<activity android:name=".SqlQrudActivity">
</activity>
<activity android:name=".ShowcaseWordsActivity"
>
</activity>
<meta-data
android:name="android.max_aspect"
android:value="4.0"/>
</application>
</manifest>
Recyclerview xml 文件
<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"
>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:title="Search Your Words"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/rvPrograms"
>
</androidx.appcompat.widget.Toolbar>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvPrograms"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
</androidx.constraintlayout.widget.ConstraintLayout>
Crud Sql xml 工具栏不是我添加但在应用程序安装后自动显示的文件
<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_height="match_parent"
android:layout_width="match_parent"
android:padding="10dp"
android:background="@color/white">
<TextView
android:id="@+id/insertID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Insert Id"
android:textSize="18sp"
android:textStyle="bold"
android:layout_marginLeft="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/updateID"
/>
<EditText
android:id="@+id/updateID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"
android:padding="10dp"
android:layout_margin="10dp"
android:background="@drawable/custom_input"
android:inputType="number"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/insertID"
app:layout_constraintBottom_toTopOf="@+id/insertText"
/>
<TextView
android:id="@+id/insertText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:text="Insert Name"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/updateID"
app:layout_constraintBottom_toTopOf="@+id/editName"
/>
<EditText
android:id="@+id/editName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textSize="18sp"
android:textStyle="bold"
android:padding="10dp"
android:background="@drawable/custom_input"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/insertText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/insertDescription"
/>
<TextView
android:id="@+id/insertDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Description"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editName"
app:layout_constraintBottom_toTopOf="@+id/editDescription"
/>
<EditText
android:id="@+id/editDescription"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="10dp"
android:hint="Add Description"
android:textSize="18sp"
android:textStyle="bold"
android:gravity="center"
android:padding="10dp"
android:background="@drawable/custom_input"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/insertDescription"
app:layout_constraintEnd_toEndOf="parent"
/>
<include layout="@layout/fragment_word_recyclerview" />
</androidx.constraintlayout.widget.ConstraintLayout>
Styles.xml 文件
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="DetailTheme">
<!-- Customize your theme here. -->
<!--
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
-->
</style>
<style name="DetailTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
片段class,其中只有我初始化的工具栏
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_word_recyclerview,container,false);
Toolbar toolbar = ((Toolbar) view.findViewById(R.id.toolbar));
AppCompatActivity activity = (AppCompatActivity) getActivity();
activity.setSupportActionBar(toolbar);
setHasOptionsMenu(true);
return view;
在“Crud Sql xml”中,接近尾声 - 你有:
<include layout="@layout/fragment_word_recyclerview" />
您可能想要删除此行。
如果您看到第二个代码片段,则此布局有工具栏和回收视图。如果您将此布局包含在“Crud Sql xml”中,您将在顶部看到工具栏。 recyclerview 可能不可见,因为您可能没有向其中添加任何内容。
Im not added toolbar in this fragment but it is overriding from Recyclerview's xml file
Im added toolbar in this specific recyclerview's xml file
清单文件
<?xml version='1.0' encoding='utf-8'?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sanskrit.mysearcher">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:resizeableActivity="false">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DisplayContactActivity">
</activity>
<activity android:name=".SqlQrudActivity">
</activity>
<activity android:name=".ShowcaseWordsActivity"
>
</activity>
<meta-data
android:name="android.max_aspect"
android:value="4.0"/>
</application>
</manifest>
Recyclerview xml 文件
<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"
>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:title="Search Your Words"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/rvPrograms"
>
</androidx.appcompat.widget.Toolbar>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvPrograms"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
</androidx.constraintlayout.widget.ConstraintLayout>
Crud Sql xml 工具栏不是我添加但在应用程序安装后自动显示的文件
<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_height="match_parent"
android:layout_width="match_parent"
android:padding="10dp"
android:background="@color/white">
<TextView
android:id="@+id/insertID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Insert Id"
android:textSize="18sp"
android:textStyle="bold"
android:layout_marginLeft="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/updateID"
/>
<EditText
android:id="@+id/updateID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"
android:padding="10dp"
android:layout_margin="10dp"
android:background="@drawable/custom_input"
android:inputType="number"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/insertID"
app:layout_constraintBottom_toTopOf="@+id/insertText"
/>
<TextView
android:id="@+id/insertText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:text="Insert Name"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/updateID"
app:layout_constraintBottom_toTopOf="@+id/editName"
/>
<EditText
android:id="@+id/editName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textSize="18sp"
android:textStyle="bold"
android:padding="10dp"
android:background="@drawable/custom_input"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/insertText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/insertDescription"
/>
<TextView
android:id="@+id/insertDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Description"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editName"
app:layout_constraintBottom_toTopOf="@+id/editDescription"
/>
<EditText
android:id="@+id/editDescription"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="10dp"
android:hint="Add Description"
android:textSize="18sp"
android:textStyle="bold"
android:gravity="center"
android:padding="10dp"
android:background="@drawable/custom_input"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/insertDescription"
app:layout_constraintEnd_toEndOf="parent"
/>
<include layout="@layout/fragment_word_recyclerview" />
</androidx.constraintlayout.widget.ConstraintLayout>
Styles.xml 文件
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="DetailTheme">
<!-- Customize your theme here. -->
<!--
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
-->
</style>
<style name="DetailTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
片段class,其中只有我初始化的工具栏
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_word_recyclerview,container,false);
Toolbar toolbar = ((Toolbar) view.findViewById(R.id.toolbar));
AppCompatActivity activity = (AppCompatActivity) getActivity();
activity.setSupportActionBar(toolbar);
setHasOptionsMenu(true);
return view;
在“Crud Sql xml”中,接近尾声 - 你有:
<include layout="@layout/fragment_word_recyclerview" />
您可能想要删除此行。
如果您看到第二个代码片段,则此布局有工具栏和回收视图。如果您将此布局包含在“Crud Sql xml”中,您将在顶部看到工具栏。 recyclerview 可能不可见,因为您可能没有向其中添加任何内容。