[英]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 并且内部onCheckedChanged把expandGroup和collapseGroup电话,取决于检查状态
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.