gpt4 book ai didi

android - 如何在单击时将最喜欢的星形图标设置为ON,在android中再次单击时将其设置为OFF

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:06:43 25 4
gpt4 key购买 nike

我的具有报价列表的 Activity 如下。

package bank.quotes.famous;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;

public class QuotesActivity extends FamousQuotesActivity {
@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.quoteslayout);

CheckBox favButton = (CheckBox)findViewById( R.id.favbutton );

我已经尝试在此处添加您的代码但没有成功。我的 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="match_parent"
android:orientation="vertical" >

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="856dp"
android:background="@android:color/white"
android:orientation="vertical" >

<TableRow
android:id="@+id/TableRow03"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25" >

<RelativeLayout
android:id="@+id/RelativeLayout08"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/forquotesgrey" >



<TextView
android:id="@+id/TextView22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/albertquote"
android:textAppearance="?android:attr/textAppearanceMedium" />


<TextView
android:id="@+id/TextView21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="@string/alberteinstein"
android:textAppearance="?android:attr/textAppearanceMedium" />


<CheckBox
android:id="@+id/favbutton"
style="?android:attr/starStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/TextView21"
android:layout_alignParentRight="true" />

</RelativeLayout>
</TableRow>

<TableRow
android:id="@+id/TableRow06"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25" >

<RelativeLayout
android:id="@+id/RelativeLayout10"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/forquotesgrey" >


<TextView
android:id="@+id/TextView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/stevequote"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black" />


<TextView
android:id="@+id/TextView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="@string/stevejob"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black" />

<CheckBox
android:id="@+id/CheckBox01"
style="?android:attr/starStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />

</RelativeLayout>
</TableRow>

如果用户喜欢某个报价,它应该转到收藏夹 Activity 。如果用户喜欢,收藏按钮也应该始终发光。这就是收藏按钮的工作方式,不是吗?这是我第一次添加收藏夹按钮,所以我不太想这样做。如果你能帮助我,我将非常感激。谢谢。

最佳答案

如果您想使用有状态的可绘制对象,您会发现为 ToggleButton 或 CheckBox 添加皮肤比为 ImageButton 更容易。

<CheckBox android:id="@+id/star" 
style="?android:attr/starStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

关于android - 如何在单击时将最喜欢的星形图标设置为ON,在android中再次单击时将其设置为OFF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8930735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com