相关疑难解决方法(0)

将不同的字体和颜色设置为TextView的一部分

我试过这个:

String s = "Some big string"
SpannableStringBuilder sb = new SpannableStringBuilder(s);
//normal font for 1st 9 chars
sb.setSpan(robotoRegular, 0,9,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
//bold font for rest of the chars
sb.setSpan(robotoBold, 9,s.length(),Spannable.SPAN_INCLUSIVE_INCLUSIVE);
//also change color for rest of the chars
sb.setSpan(new ForegroundColorSpan(Color.BLACK), 9,s.length(),Spannable.SPAN_INCLUSIVE_INCLUSIVE);
textView.setText(sb);
Run Code Online (Sandbox Code Playgroud)

但这没效果.

它只需要最新的setSpan,即..,Text颜色正在改变但不是字体.

android typeface spannablestring

8
推荐指数
1
解决办法
1万
查看次数

如何设置Android微调器弹出式样?

我已经设定

<item name="android:spinnerMode">dialog</item>
Run Code Online (Sandbox Code Playgroud)

所以当我点击微调器时,我会弹出一个弹出窗口.但是那个弹出窗口是带有白色文本的灰色,我似乎无法改变任何颜色.如何设置此对话框的样式?

我尝试了以下一些疯狂的临时颜色,看看有什么变化,但没有任何变化.

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:dialogTheme">@style/SpinnerDialog</item>
    <item name="android:alertDialogTheme">@style/SpinnerAlertDialog</item>
</style>

<style name="SpinnerDialog" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:popupBackground">#ff00ff</item>
    <item name="colorPrimary">#ff00ff</item>
    <item name="colorPrimaryDark">#ffff00</item>
    <item name="colorAccent">#ff0000</item>
</style>

<style name="SpinnerAlertDialog" parent="Theme.AppCompat.Dialog">
    <item name="colorPrimary">#00ffff</item>
    <item name="colorPrimaryDark">#00ff00</item>
    <item name="colorAccent">#0000ff</item>
</style>
Run Code Online (Sandbox Code Playgroud)

有一堆类似的问题,但它们都处理下拉列表或古老版本的Android或只是不工作.

android android-spinner android-styles

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

创建一个包含两行文本的自定义按钮,每行都有不同的字体

我有点卡在这里,可以真正使用一些帮助.在我看来,将两个单独的文本行添加到按钮应该很容易.但事实并非如此.有一种方法可以使用html标签,但这不允许您指定超出"大"和"小"的字体或文本大小.

这是我的按钮,它叫做'clicky':

   <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/buttondown"
          android:state_pressed="true" />
    <item android:drawable="@drawable/buttonup" />
</selector>
Run Code Online (Sandbox Code Playgroud)

以下是它在其中一个布局文件中显示的位置:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" 
 android:layout_width="fill_parent"
  android:layout_height="fill_parent">



<Button
        android:id="@+id/clicky"
        android:layout_width="137.5dip"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="2dip"
        android:layout_marginBottom="2dip"
        android:layout_marginRight="1dip"
        android:textSize="20dip"
        android:background="@drawable/clicky"
  />


  <ListView 
    android:id="@+id/ListView01" 
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:divider="#000000"
    android:dividerHeight="2dip"
    android:layout_below="@+id/separator"/>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这是我在onCreate()方法中的内容:

Typeface customFont = Typeface.createFromAsset(getAssets(),"fonts/zooper.ttf");
 Button mButton=(Button)findViewById(R.id.clicky);
        mButton.setText("Hi There");
        TextView clicky = (TextView)findViewById(R.id.clicky);
        clicky.setTypeface(customFont);
Run Code Online (Sandbox Code Playgroud)

按钮中的文本是动态创建的,所以我必须从这里开始(现在它是静态的,但后来"Hi There"将被替换为变量).另一行文字将更小,静态并放在"Hi There"下面.我已经浏览了谷歌上的一切,甚至远远类似于我的问题,但我找不到能够适应我的问题的答案.

所以再次,我需要一个单独的按钮,两个单独的文本行,一个在另一个之上.顶行是大的,动态创建并使用自定义字体.较低的文本行将小得多,静态并且可以使用系统字体.

将LinearLayout嵌套在按钮内是否真的太难了?

任何帮助将非常感激.

android android-layout

3
推荐指数
1
解决办法
5880
查看次数

如何在字体文本视图类中添加多种字体?

我有一个关于向textview添加多个自定义字体的问题.我基本上已经在fonts文件夹中添加了字体,并基于我在网上找到的解决方案为fonttextview创建了一个java类.但是我看到他们只添加了一种字体,我想添加多种字体,如roboto-regular,roboto-bold,cab-bold等.这是我到目前为止的代码:

public class FontTextView extends TextView {


    public FontTextView(Context context) {
      super(context);
      Typeface face=Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Bold.ttf"); 
      this.setTypeface(face);

    }

    public FontTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
     Typeface face=Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Bold.ttf"); 
  this.setTypeface(face); 
    }

    public FontTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
     Typeface face=Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Bold.ttf"); 
  this.setTypeface(face); 
    }
Run Code Online (Sandbox Code Playgroud)

如何创建多种字体呢?此外,我尝试了样式等,但它显示错误,因为它不支持可定制的类,任何人都可以添加另一种字体到这个现有的代码并引导我完成检索过程?

谢谢!贾斯汀

android android-emulator android-intent android-layout android-listview

3
推荐指数
1
解决办法
4215
查看次数