相关疑难解决方法(0)

自定义按钮有两个TextView

我正在尝试在一个按钮内使用两个带有不同字体的TextView自定义按钮.为此,我只是扩展了Button并在构造函数中编写了以下代码,

LayoutInflater layoutInflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.custom_button,
        (ViewGroup) findViewById(R.id.custom_button_view));

TextView firstTextView = (TextView) layout
        .findViewById(R.id.firstTextView);
TextView secondTextView = (TextView) layout
        .findViewById(R.id.secondTextView);
Run Code Online (Sandbox Code Playgroud)

在布局custom_button我已经放置了两个具有不同字体和文本的TextView,custom_button_view是该LinearLayout的ID,我得到的是一个没有文本的空按钮.

任何想法,谢谢.

android

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

错误:找不到与给定名称匹配的资源:attr'typeface'

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="TextViewAppearance" parent="@android:style/TextAppearance.Widget.TextView">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="typeface">robotoRegular</item>            
    </style>

    <style name="TextViewAppearance.Display1" parent="@style/TextViewAppearance">
        <item name="typeface">robotoBlack</item>
        <item name="android:textSize">45sp</item>
        <item name="android:textColor">@color/main_color_grey_500</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

获取错误: 错误:(4,5)找不到与给定名称匹配的资源:attr'typeface'.

我正在使用
1. Android Studio 1.5.1
2. minSdkVersion 15
3. targetSdkVersion 23

<-----------编辑--------------------->

我的布局文件是

<abcapp.com.font.RobotoTextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"               
                android:text="ABC"               
                android:textSize="16sp"
                app:typeface="robotoBlack" />
Run Code Online (Sandbox Code Playgroud)

java android android-support-library android-studio

5
推荐指数
1
解决办法
4286
查看次数

更改Android App的默认字体

好的,我知道如何更改我的应用程序中单个文本框上使用的字体,但我希望我的应用程序中的所有文本都使用此自定义字体和颜色,目前我能想到的唯一方法是参考每个框并将它们设置为正确的字体和颜色.虽然它可行但似乎是一种笨重的方法,有更好的方法吗?

fonts android default truetype

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

如何使用字体文件

我想使用自定义字体文件.以下是我的代码

XML文件:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/custom_font"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="This is the Chantelli Antiqua font." />
</LinearLayout> 
Run Code Online (Sandbox Code Playgroud)

Java代码:

   TextView txt = (TextView) findViewById(R.id.custom_font);  
   Typeface font = Typeface.createFromAsset(getAssets(), "Chantelli_Antiqua.ttf");  
   txt.setTypeface(font); 
Run Code Online (Sandbox Code Playgroud)

它的工作.但我想在整个项目中使用这种自定义字体.

所以我必须放在一个所有Class都可以使用它的地方.不需要为每个人写TextView.

我在哪里以及如何使用此自定义字体.

fonts android android-fonts

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