在我的应用程序中,我有 1 个活动类,对于该活动类,我设置了布局,这是另一个类文件,而不是“Xml 文件”。在那个类文件中,我试图放置一个“编辑文本”,它来了但不起作用(我无法输入任何输入,即使它是可点击的)。我在“SO”中尝试了很多帖子,但我仍然无法得到那。
我的代码:
活动:
public class MainActivity extends Activity
{
HomeDesign hm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hm = new HomeDesign(this);
setContentView(hm);
// Canvas canvas = new Canvas();
// Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.sabrerez);
// canvas.drawBitmap(image, 10, 10, null);
// ImageView img = (ImageView) findViewById(R.id.logo);
//
// img.setBackgroundResource(R.drawable.sabrerez);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
查看类:
public void draw(Canvas c)
{
brush.setColor(Color.parseColor("#617981"));
c.drawRect(0, 0, c.getWidth(), 70, brush);
c.drawBitmap(bm, 10, 10, brush);
brush.setColor(Color.parseColor("#ebecec"));
c.drawRect(0, 70, c.getWidth(),c.getHeight(), brush);
brush.setStrokeWidth(3);
brush.setColor(Color.parseColor("#617981"));
brush.setTextSize(15);
c.drawText("Username", c.getWidth()/8,c.getHeight()/2 - 100, brush);
c.drawText("Password", c.getWidth()/8,c.getHeight()/2 - 50, brush);
brush.setColor(Color.parseColor("#000000"));
FrameLayout layout = new FrameLayout(context);
username= new EditText(context);
// LinearLayout.LayoutParams params2 = (LinearLayout.LayoutParams) username.getLayoutParams();
// LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(40,40);
// username.setText("" + i);
username.setFocusableInTouchMode(true);
username.setFocusable(true);
username.requestFocus();
username.setEnabled(true);
username.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
username.setInputType(InputType.TYPE_CLASS_TEXT);
layout.measure(c.getWidth(),c.getHeight());
// layout.
layout.layout(10, 200, 100, 220);
// layout.layout(c.getWidth()/8+100,c.getHeight()/2 - 110 - 10,c.getWidth()/8+250,c.getHeight()/2 - 100 + 10);
// layout.layout(100,100,100,80);
layout.draw(c);
}
如何解决这个问题?