在我的應用程序中,我想創建一個可以作爲.java文件重用的Search部件,我需要將它反映到layout.xml文件中,以便我可以用它。直接.....這裏是我的代碼有一個編輯框,兩個按鈕。如何在Android佈局.xml中爲coustom查看java文件查看組
public class SearchWidget extends ViewGroup{
Context mContext;
LinearLayout layout;
EditText edit;
Button searchButton;
Button clear;
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
public SearchWidget(Context context) {
super(context);
this.mContext=context;
layout=new LinearLayout(context);
edit=new EditText(context);
searchButton=new Button(context);
clear=new Button(context);
params.setMargins(10, 10, 10, 10);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setLayoutParams(params);
edit.setMaxLines(1);
edit.setWidth(100);
layout.addView(searchButton);
layout.addView(clear);
}
}
請建議我如何給這個Java文件的參考我layout.xml 先謝謝了。
@Blessenm嗨,我得到這個,但現在我真的不能讓我的佈局屏幕則僅顯示黑屏,可以你提供任何鏈接,其中給出了完整的例子謝謝.... –
我更新了我的答案 – blessenm
它沒有解決問題,通過應用此......只有黑屏正在顯示/// –