how to Custom Button (has two TextFields) on Android

前端 未结 2 1417
有刺的猬
有刺的猬 2021-01-07 07:26

I need to develop a button that has two label in.

I find some good articles about custom views, but I can\'t imagine that how can I create a myButton Class(with cus

2条回答
  •  误落风尘
    2021-01-07 07:42

    You can create a custom view. I have used Layout as a button by setting custom button style to the layout and have added two textViews to it, this way:

    
    
    
    
    

    and in Activity you can have this to set different typeface:

    Typeface font=Typeface.createFromAsset(getAssets(),"ARIALN.TTF") ;   
    Typeface font2=Typeface.createFromAsset(getAssets(), "COMPCTAN.TTF");
    
    TextView firstTextView = (TextView)findViewById(R.id.firstTextView);
    TextView secondTextView = (TextView)findViewById(R.id.secondTextView);
    
    firstTextView.setTypeface(font);
    secondTextView.setTypeface(font2);
    
    LinearLayout btnLayout=(LinearLayout) findViewById(R.id.customButtonLayout);
    btnLayout.setOnClickListener(this);
    

提交回复
热议问题