您好,我想在加载 Activity 时禁用线性布局的所有内容,当用户单击这些内容时,它会显示警报消息。
单击激活按钮后,应启用线性布局。可不可以?
我可以使用以下代码禁用线性布局内的所有内容:
LinearLayout myLayout = (LinearLayout) findViewById(R.id.linearLayout1);
for ( int i = 0; i < myLayout.getCount(); i++ ){
View view = myLayout.getChildAt(i);
view.setVisibility(View.GONE); // Or whatever you want to do with the view.
}
我想在用户点击禁用区域时显示警告对话框。
请给我建议可用的链接或示例代码。
最佳答案
您需要做如下操作:
LinearLayout myLayout = (LinearLayout) findViewById(R.id.linearLayout1);
for ( int i = 0; i < myLayout.getChildCount(); i++ ){
View view = myLayout.getChildAt(i);
view.setEnabled(false); // Or whatever you want to do with the view.
}
然后创建一个alert Dialog然后
myLayout.setOnclickListener(new OnClickListener(){
onClick(){
dialog.show();
}
});
关于android - 如何禁用android中线性布局内的所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9081156/