gpt4 book ai didi

android - 如何使我自己的小部件在 XML 布局文件中使用

转载 作者:行者123 更新时间:2023-11-30 03:05:28 26 4
gpt4 key购买 nike

我见过使用自定义小部件的 xml 文件,例如,google 登录按钮...

<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:foreground="@drawable/log_in" />

我发现如果你在你的包中创建一个扩展 ViewGroup 的类,你可以说例如... <com.example.myApp.MyCustomViews等等等等

所以现在我有这门课...

public class ChatUILayout extends ViewGroup {

public ChatUILayout(Context context) {
super(context);
// TODO Auto-generated constructor stub
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub

}

}

我希望这个聊天用户界面布局包含一个 EditText , TextView , 和一个 Button当我从 xml 中引用它时,我该如何实现它?

最佳答案

据我了解,您需要使用布局充气器。

填充 xml (ChatUILayout),当您填充该 View 时,您将使用 findViewById(R.id.YourEditText)、findViewById(R.id.YourTextView) 等,然后设置必要的值并单击处理程序。

View view = LayoutInflater.from(getBaseContext()).inflate(R.layout.ChatUILayout),
null);

关于android - 如何使我自己的小部件在 XML 布局文件中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21897374/

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