简体   繁体   English

如何向我的应用添加展开/关闭图标?

[英]How Can I Add an Expand/Close Icon to My App?

I have created an expandable/collapsible list after following a tutorial for my app in Android Studio, however I'm wanting to add a button which is aligned left of the heading which changes to an up/down button when a heading is expanded/collapsed. 我在按照Android Studio中的应用程序教程学习后创建了一个可扩展/可折叠列表,但是我想添加一个与标题左对齐的按钮,当标题被扩展/折叠时,该按钮变为向上/向下按钮。 How can I add this? 如何添加呢?

My activity files for the expandable and collapsible list are as follows: 我针对可扩展和可折叠列表的活动文件如下:

list_main.xml: list_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#f4f4f4" >

<ExpandableListView
    android:id="@+id/lvExp"
    android:layout_height="match_parent"
    android:layout_width="match_parent"/>

</LinearLayout>

list_group.xml: list_group.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:background="#000000">


<TextView
    android:id="@+id/lblListHeader"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
    android:textSize="17dp"
    android:textColor="#f9f93d" />

</LinearLayout>

list_item.xml: list_item.xml:

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

<TextView
    android:id="@+id/lblListItem"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="17dip"
    android:paddingTop="5dp"
    android:paddingBottom="5dp"
    android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" />

</LinearLayout>

I've tried to implement it by changing the layout file of list_group.xml to: 我试图通过将list_group.xml的布局文件更改为实现它:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:background="#000000">


<selector xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <item android:drawable="@drawable/down_squared"  android:state_checked="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <item android:drawable="@drawable/up_squared"  android:state_checked="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</selector>

<TextView
    android:id="@+id/lblListHeader"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
          android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
    android:textSize="17dp"
    android:textColor="#f9f93d" />

</LinearLayout>

However the page keeps crashing now and there the design tab says there are rendering errors, which are: 但是,该页面现在仍然崩溃,并且“设计”选项卡上显示存在渲染错误,这些错误是:

The following classes could not be found: - item (Fix Build Path, Edit XML) - selector (Fix Build Path, Edit XML) 找不到以下类:-项目(修复构建路径,编辑XML)-选择器(修复构建路径,编辑XML)

Use checkbox with background set as your drawable 使用背景设置为可绘制的复选框

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/play_icon" android:state_checked="true" />
<item android:drawable="@drawable/pause_icon" android:state_checked="false" />
</selector>

then in your code set a callback for checkbox setOnCheckedChangeListener 然后在您的代码中设置复选框setOnCheckedChangeListener的回调

and inside the onCheckedChanged put expandGroup and collapseGroup calls, depending on the check state 并且内部onCheckedChangedexpandGroupcollapseGroup电话,取决于检查状态

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

相关问题 如何以编程方式在Android应用程序中展开通知栏? - How can I programmatically expand the notifications bar in my android app? 如何在RubyMotion Android应用中添加图标? - How do I add an icon to my RubyMotion Android app? 如何从Android自定义通知中删除header信息(包括小图标、应用名称)和展开图标? - How can I remove header information (which includes small icon, app name) and expand icon from the Android custom notification? 关闭我的应用程序时如何清除缓存? - How can I clear cache when I close my app? 如何在单击应用程序图标时关闭画中画活动。 我的应用程序中有多项活动? - How to close PIP picture in picture activity on click of application icon. I have multiple activities in my app? 如何将文件夹图标添加到我的列表视图 - How can I add folder icon to my listview 如何在Android中将动作栏应用程序图标设置为onClickListner? - How can I set my actionbar app icon onClickListner in Android? 如何更改我的Android应用程序的图标 - How can i change icon of my android app 如何在我的 flutter 应用程序中使汉堡图标更大 - how can i make the burger icon bigger in my flutter app 如何关闭/退出应用程序上的按钮? - How i can close/exit button on my app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM