我正在尝试使用android 4.0实现片段.我在DummyContent.java文件中添加了列表片段中的三个项目
static {
// Add 3 sample items.
addItem(new DummyItem("1", "Videos"));
addItem(new DummyItem("2", "Images"));
addItem(new DummyItem("3", "Story"));
}
Run Code Online (Sandbox Code Playgroud)
这些视频,图像,故事出现在片段左侧,每个项目的点击显示右侧细节片段的详细信息.
我想更改这些列表视图的字体,但问题是列表片段使用系统textview如下所示
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO: replace with a real list adapter.
setListAdapter(new ArrayAdapter<DummyContent.DummyItem>(getActivity(),
android.R.layout.simple_list_item_activated_1,
android.R.id.text1, DummyContent.ITEMS));
}
Run Code Online (Sandbox Code Playgroud)
哪个不允许我应用字体 android.R.id.text1
请帮我
android android-layout android-fonts android-fragments android-listfragment
我开发了一个Android应用程序来处理小型,中型和大型屏幕尺寸的设备.
但最近我遇到了以下问题.
当我进入设置并将字体大小更改为超大而不是默认的中等大小[设置 - >显示 - >字体大小]时,我的应用程序字体大小也相应增加,布局变得混乱.
有任何人以前经历过这一点,并将感谢任何想法的解决方案,不会继续这种混乱的情况.
编辑...
我使用"sp"单位来定义应用程序中的所有字体大小...
我正在开发一个应用程序.我正在使用自定义字体.".ttf"文件来自定义文本视图的字体.我使用的代码如下:
Typeface tfArchitectsDaughter = Typeface.createFromAsset(getAssets(), "fonts/ArchitectsDaughter.ttf");
textview.setTypeface(tfArchitectsDaughter);
Run Code Online (Sandbox Code Playgroud)
现在需要的是:我想让文本自定义,如上所述,以及.java文件中的BOLD样式.
怎么做请建议.还有什么其他样式或定制可以在字体上做,请建议.
谢谢.
在我的代码中有一个巨大的问题,我在assets\fonts\
自定义TextView
类中加载我的文件夹中的字体.第一个问题是它在4.0设备上崩溃,但有例外Caused by: java.lang.RuntimeException: native typeface cannot be made
.我在这里使用相同的过程:
public class MyTextView extends TextView {
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyTextView(Context context) {
super(context);
}
public void setTypeface(Typeface tf, int style) {
if (style == Typeface.BOLD) {
super.setTypeface(Typeface.createFromAsset(
getContext().getAssets(), "fonts/hirakakupronbold.ttf"));
} else if (style == Typeface.ITALIC) {
super.setTypeface(Typeface.createFromAsset(
getContext().getAssets(), "fonts/hirakakupronitalic.ttf"));
} else {
super.setTypeface(Typeface.createFromAsset(
getContext().getAssets(), "fonts/hirakakupron.ttf")); …
Run Code Online (Sandbox Code Playgroud) android memory-leaks android-fonts runtimeexception inflate-exception
我遇到的问题是特定于Android 5.0(包括5.0.1/5.0.2)的手机和我的平板电脑(Nexus 9).早期版本的Android工作正常.
在我的应用程序中,我想设置一个覆盖所有文本的全局字体.我在5.0之前完成此操作的方法是使用此方法.这种字体覆盖方法似乎不适用于我尝试过但在2.x和4.x中完美运行的任何版本的Lollipop.我也在这段代码运行在一个BaseApplication
类我有这样的字体是唯一的初始化onCreate()
我的BaseApplication
.
这似乎是开发人员预览版中的一个错误并在此处报告.我尝试了在第16篇文章中建议的修复,使用TTX工具将您的字体文件转换为.ttx并返回到.otf,但这似乎没有像其他人那样解决问题.我还验证了我的.otf字体文件是有效的,并且没有根据OTS清理工具损坏.
我还有一个自定义TextView,我可以通过布局设置字体.一个例子是:
<com.myapp.widgets.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Testing text view font"
myapp:fontName="my-font.otf" />
Run Code Online (Sandbox Code Playgroud)
此CustomTextView setTypeface(typeFace)
在视图的初始化中用于设置字体.这适用于5.0,但实际上并不是我可以使用的解决方案,因为我需要遍历每个布局并更改TextView,EditText等以使用CustomTextView,并且无法使用Dialog文本枯萎.
因此,使用我的CustomTextView类设置单个TextView的字体在所有Android版本中都可以正常工作,而不是全局设置.
我还查看了样式源代码,看看我是否能找到Material和Holo主题之间的任何差异,但似乎没有什么会改变它android:typeface
.我最初的想法是,Material主题在某种程度上覆盖android:typeface
了我的应用主题的属性,但我无法找到任何东西.
任何想法或意见将不胜感激,谢谢!
我正在使用 Jetpack Compose 学习 android native,当我想分配文本的字体大小时,我找到了两种方法来实现它,使用 fontSize 属性和使用 TextStyle.fontSize 属性,但是,这两种方法有不同的行为,线的高度根据我分配的属性而变化:
我想知道为什么会发生这种情况以及我应该继续使用这两个选项中的哪一个,非常感谢。
我想使用我的自定义字体与WebViewb
我的html文件加载在webView但仍然没有字体
我的字体有Unicode字符
我工作在Android 2.2
mWebView.loadUrl("file:///android_asset/P_007.html");
Run Code Online (Sandbox Code Playgroud)
我的css:
<STYLE type="text/css">
@font-face {
font-family: AQF_P007_HA;
src: url("AQF_P007_HA.TTF");
}
body {
font-family: AQF_P007_HA;
font-style:normal;
font-weight: normal;
color: black;
font-size: medium;
mso-font-charset: 0
}
</STYLE>
Run Code Online (Sandbox Code Playgroud) I have a custom fonts BebasNeue.otf
which i want to set in the strings variables. I have searched a lot but did not get any solution.
I know we can set the custom fonts in views like textView.setTypeface(font);
. But now i want to set the fonts to the Strings
which i have as below :
String Name,Contact;
Name="ABCD";
Contact="97696538";
Run Code Online (Sandbox Code Playgroud)
This all the strings contains some values. Now i want to set the custom fonts to all the strings which …
我对字体不太熟悉,所以这个问题可能是由于我的无知.
我有一个字体文件,Futura.tcc.在代码中我有以下内容:
Typeface face=Typeface.createFromAsset(am, "fonts/Futura.ttc");
editText.setTypeface(face);
Run Code Online (Sandbox Code Playgroud)
这适用于基本的Futura字体.但是,我的客户端发送的文件包含多个字体子类型(如果这是正确的术语).我知道setTypeFace()
接受类型为int的第二个参数是样式.但是,传递各种价值观无济于事.
如果此文件包含名为"Futura Light"的字体,我如何告诉它使用该字体,而不仅仅是常规的Futura字体?
谢谢!
我有一个用于自定义字体的书法库,该库似乎可以在除android Q之外的所有版本上使用,在启动时它使我的应用程序崩溃。最近还有其他人必须处理相同的问题吗?这是我的崩溃报告:
Caused by: android.view.InflateException: Binary XML file line #17 in com.myapp.dev:layout/abc_screen_simple: Binary XML file line #17 in com.myapp.dev:layout/abc_screen_simple: Error inflating class android.support.v7.widget.FitWindowsLinearLayout
Caused by: android.view.InflateException: Binary XML file line #17 in commyapp.dev:layout/abc_screen_simple: Error inflating class android.support.v7.widget.FitWindowsLinearLayout
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Field.get(java.lang.Object)' on a null object reference
at uk.co.chrisjenx.calligraphy.ReflectionUtils.getValue(ReflectionUtils.java:29)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(CalligraphyLayoutInflater.java:203)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access$000(CalligraphyLayoutInflater.java:20)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:302)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:239)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1069)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.inflate(LayoutInflater.java:659)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at android.support.v7.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:631)
at android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518) …
Run Code Online (Sandbox Code Playgroud) android android-custom-view android-fonts android-library android-10.0
android ×10
android-fonts ×10
fonts ×4
android-10.0 ×1
android-ui ×1
android-xml ×1
css ×1
java ×1
kotlin ×1
memory-leaks ×1
textview ×1