【问题标题】:android common footer with dynamic data to all activitiesandroid通用页脚,所有活动的动态数据
【发布时间】:2023-03-17 02:38:01
【问题描述】:

谁能告诉我如何使用基于加载的活动的动态数据为应用程序中的所有活动设置页脚?

我需要从所有活动的列表视图中将页脚文本更改为选定的学生,如果没有学生选择显示“GUEST”

【问题讨论】:

  • 您可以使用片段活动,并在其中从整个应用程序使用片段中设置页脚,您可以从任何地方更改页脚。
  • 能否请您提供示例,我一直在尝试这样做,但无法将片段与父活动的底部对齐,并且背景图像也丢失了。

标签: android dynamic footer


【解决方案1】:

制作一个footer.xml 并将其包含在要显示的所有activity.xml 中。然后根据您的要求进行更改。

【讨论】:

  • 如何从父活动中更改包含的文件?
  • 是的,你可以,在 onCreate 方法中使用 findviewbyid() 获取 id 并对其进行更改。
  • 关注了这个链接stackoverflow.com/questions/6605588/…这给了nullpointerexception错误
【解决方案2】:

只需查看此 xml,它是您在框架容器中的要求的简单 xml,您可以替换所有片段。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:background="@color/blue">

    <ImageView

        android:layout_width="@dimen/main_drawer_icon"
        android:layout_height="@dimen/main_drawer_icon"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginBottom="@dimen/library_screen"
        android:layout_marginLeft="@dimen/smallText"
        android:src="@mipmap/arrow_left_white"
        android:visibility="gone" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text=" Header"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/white" />

    </RelativeLayout>

<View
    android:layout_width="match_parent"
    android:layout_height="5dp"
    android:background="@color/orange"></View>

<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_weight="0.90"
    android:layout_height="0dp">


   <--  Replace here yout fragments -->


</FrameLayout>


<View
    android:id="@+id/viewDestination"
    android:layout_width="match_parent"
    android:layout_height="0.01dp"
    android:background="@color/greyMediumlight" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.10"
    android:orientation="vertical">



         <--  This is Footer View -->


</LinearLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    • 2018-09-28
    • 2012-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-08
    相关资源
    最近更新 更多