ata*_*oyh 2 android custom-view android-layout
我需要开发一个有两个标签的按钮.
我找到一些关于自定义视图的好文章,但我无法想象如何创建一个myButton类(其中包含自定义布局)扩展按钮...是否可能..
另外在XML中有些视图,布局......我们怎么能这样做?
小智 5
您可以创建自定义视图.我已经使用布局作为按钮,通过设置自定义按钮样式到布局,并添加了两个textViews,这样:
<LinearLayout android:id="@+id/customButtonLayout"
android:layout_height="wrap_content" style="@android:style/Widget.Button"
android:layout_width="wrap_content">
<TextView android:text="First" android:id="@+id/firstTextView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="#000"></TextView>
<TextView android:textColor="#000" android:text="Second"
android:layout_height="wrap_content" android:id="@+id/secondTextView"
android:layout_width="wrap_content" android:layout_marginLeft="10dp"></TextView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在Activity中你可以设置不同的字体:
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);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2654 次 |
最近记录: |