相关疑难解决方法(0)

是否可以在TextView中包含多个样式?

是否可以为TextView中的不同文本设置多个样式?

例如,我将文本设置如下:

tv.setText(line1 + "\n" + line2 + "\n" + word1 + "\t" + word2 + "\t" + word3);
Run Code Online (Sandbox Code Playgroud)

是否可以为每个文本元素设置不同的样式?例如,line1粗体,word1斜体等.

开发人员指南的常见任务和Android中的操作方法包括选择,突出显示或设置部分文本样式:

// Get our EditText object.
EditText vw = (EditText)findViewById(R.id.text);

// Set the EditText's text.
vw.setText("Italic, highlighted, bold.");

// If this were just a TextView, we could do:
// vw.setText("Italic, highlighted, bold.", TextView.BufferType.SPANNABLE);
// to force it to use Spannable storage so styles can be attached.
// Or we could specify that in the XML.

// …
Run Code Online (Sandbox Code Playgroud)

android styles textview

532
推荐指数
12
解决办法
26万
查看次数

Android Toast with multi-colors

I want a toast with multi-colors. Like this:

多色吐司

I looked at the different tutorials on changing the layout in the xml to create a custom Toast, but none of them explain adding different colors like this.

How can I do this?

================================

ANSWER

================================

Using all your help, I have designed a simple Method() to make color toasts easier to call.

res/layout/toast_layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toast_layout_root"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingLeft="12dp"
    android:paddingRight="12dp"
    android:paddingBottom="6dp"
    android:paddingTop="6dp"
    android:background="#DAAA"
    >
    <TextView android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
</LinearLayout> …
Run Code Online (Sandbox Code Playgroud)

layout android colors toast

2
推荐指数
1
解决办法
1853
查看次数

我们可以在同一个EditText中编写彩色文本吗?

我使用Android Studio.我想在下面的照片中写出彩色文字EditText.我研究过,但我什么都没发现.谁能帮我?

样本输出如下.

照片

这是我的代码.anaM_LV_BG_text是列表视图name_title,内容是edittextrenk_koduları_string_text是一个包含html颜色的数组

private void registerClickCallBack_text(){anaM_LV_BG_renk_text.setOnItemClickListener(new AdapterView.OnItemClickListener(){

   private void registerClickCallBack_text() {
        anaM_LV_BG_renk_text.setOnItemClickListener(new AdapterView.OnItemClickListener() {


            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(DisplayNote.this, position + 1 + " . seçildi", Toast.LENGTH_SHORT).show();
                name_title.setTextColor(Color.parseColor(renk_kodular?_string_text[position]));
                content.setTextColor(Color.parseColor(renk_kodular?_string_text[position]));
               SharedPreferences preferences_text = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                SharedPreferences.Editor editor_text = preferences_text.edit();

                String color_text= renk_kodular?_string_text[position];
                editor_text.putString("MyColorText",color_text);
                editor_text.commit();

            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

android android-edittext

2
推荐指数
1
解决办法
106
查看次数

标签 统计

android ×3

android-edittext ×1

colors ×1

layout ×1

styles ×1

textview ×1

toast ×1