相关疑难解决方法(0)

72
推荐指数
3
解决办法
3万
查看次数

Android自定义字体可跨越字体跨度

我在整个应用程序中使用Helvetica字体.目前我正在与资产分开创建字体.所以我说这三个

HelveticaNeue = Typeface.createFromAsset(application.getAssets(), "fonts/HelveticaNeue.ttf");
HelveticaNeueBold = Typeface.createFromAsset(application.getAssets(), "fonts/HelveticaNeueBold.ttf");
HelveticaNeueBoldItalic = Typeface.createFromAsset(application.getAssets(), "fonts/HelveticaNeueBoldItalic.ttf");
Run Code Online (Sandbox Code Playgroud)

当我为一个TextView使用一种字体时,一切都很好用.但是,我需要使用spannable

Spannable WordtoSpan = new SpannableString("This text should be normal, but this needs to be bold, and normal");    
WordtoSpan.setSpan(new TypefaceSpan("bold"), 5, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Run Code Online (Sandbox Code Playgroud)

而且我想让部分字符串为HeleveticaNeueBold,而有些则只是HelveticaNeue.我认为我需要的是向Android表明上面的3种字体实际上是相关的,以便它可以很好地切换它们.寻找任何其他方式来做到这一点.

android textview custom-font typeface

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

如何在TextView中创建垂直对齐的上标和下标

在下图中的示例中:

在此输入图像描述

如何使上标和下标数字对齐以产生如下的常见科学记数法

在此输入图像描述

TextView?如果有使用的方式SpannableReplacementSpan我想看到一个有效的例子.谢谢.

android superscript textview subscript

14
推荐指数
1
解决办法
3387
查看次数

在PreferenceScreen中设置文本的自定义字体

我的PreferenceActivity看起来像:

import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.widget.TextView;

public class Settings extends PreferenceActivity {

    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
            super.onCreate(savedInstanceState);

            //setContentView(R.layout.about);

            Typeface timesFont = Typeface.createFromAsset(getAssets(), "fonts/times.ttf");

            TextView about_txt = (TextView) findViewById(R.id.about_txt);        
            about_txt.setTypeface(timesFont);
            about_txt.setText(R.string.about_txt);


            if (Build.VERSION.SDK_INT<Build.VERSION_CODES.HONEYCOMB)
            {
                addPreferencesFromResource(R.xml.preferences);
            } else {
                // Display the fragment as the main content.
                getFragmentManager().beginTransaction().replace(android.R.id.content,
                        new PrefsFragment()).commit();
            }
    }

    public static class PrefsFragment extends PreferenceFragment 
    {
            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);

                // Load the preferences from an XML resource …
Run Code Online (Sandbox Code Playgroud)

android preferenceactivity android-preferences

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

用于新TypefaceSpan(字体)的Android TypefaceSpan NoSuchMethodError

我正在TextView从库中应用自定义字体,字体文件存储在app文件夹的res/font中.

我用的是字体

int id = context.getResources.getIdentifier("xxx","font",packageName);
Typeface typeface = context.getResources.getFont(id);
Run Code Online (Sandbox Code Playgroud)

字体不为空,我已经调试并验证了调试点.

TypefaceSpan span = new TypefaceSpan(typeface);
Run Code Online (Sandbox Code Playgroud)

现在我想从这个字体创建TypefaceSpan对象,我遇到错误和应用程序崩溃.

java.lang.NoSuchMethodError:类Landroid/text/style/TypefaceSpan中没有直接方法(Landroid/graphics/Typeface;)V; 或其超类('android.text.style.TypefaceSpan'的声明出现在/system/framework/framework.jar!classes2.dex中).

请帮忙.提前致谢.

fonts android android-typeface

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

如何在TextView文本中为单词设置自定义字体

我想为一个单词设置自定义字体,该单词出现在字符串中的任何位置.

例:海@abc你好吗?亲爱的朋友你好,你在哪里@abc

在上面的例子中,我必须为"abc"应用自定义字体.我尝试过Spannable类,但我无法得到它.

final TextView txtComments = (TextView)view.findViewById(R.id.tv_comments);  
SpannableStringBuilder SS = new SpannableStringBuilder(alcomments.get(i));
SS.setSpan (new CustomTypefaceSpan("", tf), 0, SS.length(),Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
txtComments.setText(SS);
Run Code Online (Sandbox Code Playgroud)

但它影响整个字符串.请指导我如何实现它.

android textview custom-font spannablestring

6
推荐指数
1
解决办法
2064
查看次数

Android AlertDialog 标题字体

我正在尝试更改android.support.v7.app.AlertDialog标题文本的字体。

方法一:

   TextView title = (TextView) dialog.findViewById(android.R.id.title); //returns null
Run Code Online (Sandbox Code Playgroud)

方法二:

   final int titleId = context.getResources().getIdentifier("alertTitle", "id", "android");
   TextView title = (TextView) dialog.findViewById(titleId); //Also returns null.
Run Code Online (Sandbox Code Playgroud)

有没有其他方法可以获得标题TextView

请注意,我不想使用自定义布局。

谢谢。

android android-alertdialog

6
推荐指数
2
解决办法
5533
查看次数

我们如何使用样式自定义警告对话框的字体?

我们如何使用样式自定义android警报对话框的字体

我找到了很多使用setTypeFace()方法的解决方案。但我想使用样式自定义整个应用程序警报对话框。

我想更改标题、消息、按钮字体。

我能够使用以下代码更改消息字体。

我的警报对话框样式声明

<style name="MyAlertDialougeTheme" parent="@android:style/Theme.Material.Light.Dialog.Alert">
    <item name="android:textAppearanceSmall">@style/MyTextAppearance</item>
    <item name="android:textAppearanceLarge">@style/MyTextAppearance</item>
    <item name="android:textAppearanceMedium">@style/MyTextAppearance</item>

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

显示警报对话框的 Java 代码

 AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this,
                R.style.MyAlertDialougeTheme);
        builder.setTitle("Warning")
                .setMessage("My message here")
                .setPositiveButton("yes", null)
                .setNegativeButton("no", null)
                .show();
Run Code Online (Sandbox Code Playgroud)

在屏幕下方查看

在此处输入图片说明

请帮助我使用样式更改标题和按钮字体,我还想自定义负按钮和正按钮的字体颜色。

提前感谢您的时间和帮助!!

android android-alertdialog android-styles material-design

6
推荐指数
1
解决办法
948
查看次数

在android中的按钮中将不同的字体应用于文本

我正在创建一个重新加载的android按钮.它想要在按钮中同时包含图标和文本,所以我使用的是fontawesome.但是如何在按钮文本上同时应用我在我的应用程序中使用的fontawesome字体和自定义字体.

java android font-awesome

4
推荐指数
1
解决办法
1886
查看次数

BottomNavigationView - 如何更改菜单项字体?

我正在使用BottomNavigationView来管理片段.是否有一个简单的变更标签项字体解决方案?我使用了SpannableStringBuilder.但它不起作用.

       for (int i = 0; i < bottomBar.getMenu().size(); i++) {
            MenuItem menuItem = binding.bottomBar.getMenu().getItem(i);
            SpannableStringBuilder title = new SpannableStringBuilder(menuItem.getTitle());
            title.setSpan(mTypeface, 0, title.length(), 0);
            menuItem.setTitle(title);
        }
Run Code Online (Sandbox Code Playgroud)

android bottomnavigationview

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