Write Multiline Text On Button In Android February 01, 2024 Post a Comment I want to know, How to write Multiline Text on Button Solution 1: Use (new line)example:-android:text="Hi Hello"CopyOR1) Define in ../res/values/strings.xml: <string name="multilines">Line1Line1\nLine2Line2</string> Copy2) Refer it in the layout file:<Buttonandroid:id="@+id/btn_multilines"android:text="@string/multilines"android:layout_height="wrap_content"android:layout_width="fill_parent"></Button>CopySolution 2: Why dont you try this by codingString styledText = "<small><fontcolor='#000000'>" + "Mon-Sat 5:00 pm" + "</font></small>"+ "<br/>" + "<small><fontcolor='#000000'>" + "Closed on Sunday" + "</font></small>"; sendrequest.setText((Html .fromHtml(styledText))); CopySolution 3: you can achieve using this.1->create a button in layout as <Button android:id="@+id/buton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Mon - Sat 5 pm\nClosed on sunday" /> Copy2-> Add this class in your project.import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.PixelFormat; import android.graphics.drawable.Drawable; publicclassTextDrawableextendsDrawable { privatefinal String text; privatefinal Paint paint; publicTextDrawable(String text) { this.text = text; this.paint = newPaint(); paint.setColor(Color.WHITE); paint.setTextSize(20f); paint.setAntiAlias(true); paint.setFakeBoldText(true); paint.setShadowLayer(6f, 0, 0, Color.BLACK); paint.setStyle(Paint.Style.FILL); paint.setTextAlign(Paint.Align.LEFT); } @Overridepublicvoiddraw(Canvas canvas) { canvas.drawText(text, 0, 0, paint); } @OverridepublicvoidsetAlpha(int alpha) { paint.setAlpha(alpha); } @OverridepublicvoidsetColorFilter(ColorFilter cf) { paint.setColorFilter(cf); } @OverridepublicintgetOpacity() { return PixelFormat.TRANSLUCENT; } } Copy3-> add these lines in your activity classButton button=(Button)findViewById(R.id.button); button.setCompoundDrawables( new TextDrawable("Hour"), null, null, null); CopySolution 4: Use (new line)android:text="Hours Mon - sat 5pm"CopySolution 5: For Android layout, multiple lines of text could be added to the elements.Create a new variable with the character endOfLine "\n" in the res/values/strings.xml.For example:<string name="multiplelines">Line1 \n Line2</string> CopyRefer it in the layout file. For example, <Buttonandroid:id="@+id/start"android:text="@string/multiplelines"android:layout_height="wrap_content"android:layout_width="fill_parent"></Button>Copy Share Post a Comment for "Write Multiline Text On Button In Android"
Post a Comment for "Write Multiline Text On Button In Android"