所以我想android:fontFamily在Android中更改,但我没有在Android中看到任何预定义的字体.如何选择其中一个预定义的?我真的不需要定义自己的TypeFace,但我所需要的只是它现在所显示的内容.
<TextView
android:id="@+id/HeaderText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="52dp"
android:gravity="center"
android:text="CallerBlocker"
android:textSize="40dp"
android:fontFamily="Arial"
/>
Run Code Online (Sandbox Code Playgroud)
看来我在那里做的不会真的有效!BTW android:fontFamily="Arial"是一次愚蠢的尝试!
我需要实现自己的属性,如in com.android.R.attr
在官方文档中找不到任何内容,因此我需要有关如何定义这些attrs以及如何在我的代码中使用它们的信息.
我在我的应用程序中使用Roboto light字体.要设置字体,我要添加android:fontFamily="sans-serif-light"到每个视图.有没有办法将Roboto字体声明为整个应用程序的默认字体系列?我尝试过这样但它似乎没有用.
<style name="AppBaseTheme" parent="android:Theme.Light"></style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:fontFamily">sans-serif-light</item>
</style>
Run Code Online (Sandbox Code Playgroud) 我想在点击或聚焦时更改按钮的背景图像.
这是我的代码:
Button tiny = (Button)findViewById(R.id.tiny);
tiny.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Button tiny = (Button)findViewById(R.id.tiny);
tiny.setBackgroundResource(R.drawable.a9p_09_11_00754);
TextView txt = (TextView)findViewById(R.id.txt);
txt.setText("!---- On click ----!");
}
});
Run Code Online (Sandbox Code Playgroud)
这段代码对吗?它会在事件中调用一个按钮吗?
我确信有一个简单的答案,但我无法找到它所以我把它扔进stackoverflow ...... ;-)
我将把它作为一个例子.我有一个Android应用程序,用户可以在首选项中选择主题 - 深色或浅色主题.根据所选主题,我必须在我的应用程序中调整20种颜色.所以我希望我可以在主题中定义颜色,然后在我的TextViews等中使用这些如此定义的颜色的名称.但到目前为止,我无法弄清楚如何做到这一点,在这里和那里找不到任何解决方案.我真的不想为这20种颜色中的每种颜色定义一个额外的黑暗和浅色样式,但到目前为止这似乎是我能找到的唯一解决方案.
非常感谢任何提示
马丁:
更新:
在伪语法中,这就是我正在寻找的.可能吗?
<style name="AppTheme.MyDark" parent="android:Theme">
-?-> titleColor = "#ffffff"
-?-> introColor = "#ffaaaa"
</style>
<style name="AppTheme.MyLight" parent="android:Theme.Light">
-?-> titleColor = "#000000"
-?-> introColor = "#004444"
</style>
<TextView
android:id="@+id/quoteTitle"
android:textColor=@titleColor
...
</TextView>
<TextView
android:id="@+id/quoteIntro"
android:textColor=@introColor
...
</TextView>
Run Code Online (Sandbox Code Playgroud) 我有一种强调色,我在整个布局中使用它.我把它定义为我应用于TextView的样式.
我的应用程序允许用户在黑暗主题和浅色主题之间进行选择.我想根据所选主题调整强调色.
我应该如何根据所选主题控制我的强调色?
开发指南提供了一个使用自定义颜色的主题示例,它接近我想要的.我需要能够在运行时更改颜色.我知道我可以进入我的代码和X使用这种风格的地方我可以把组件磨掉并按照这种方式设置颜色.但我认为我可以通过风格/主题的某种组合来实现这一目标.
谢谢
android中fontFamily和typeFace有什么区别?当然,我阅读了android开发者网站上的所有描述,但我还不清楚.
根据两个词的一般含义,它应该是相同的含义.但是在android xml属性(textview ...)中,它有两个属性.这让我非常困惑.
据我所知.... fontFamily和typeFace是一组相同的字体.(Roboto,Arial)字体是fontFamily的特定字体.(Roboto-18pt-Bold,Arial-10pt-Italic)
我错过了什么?
我找不到任何关于以下差异的信息:
android:textColor="?attr/colorPrimary"
Run Code Online (Sandbox Code Playgroud)
对比
android:textColor="?colorPrimary"
Run Code Online (Sandbox Code Playgroud)
我读过“?attr”表示当前主题中指定的属性值,但没有“attr”它会给出相同的结果(=我的主题中定义的颜色)。它的行为与其他属性相似吗?
例如:
是否android:background="?attr/selectableItemBackground"
等于android:background="?selectableItemBackground"?
非常感谢。
我想创建两个主题,GrayTheme和RedTheme,它们修改一个样式属性.例如,这里是我的两个主题,默认字体颜色是白色,这对两个主题都很好:
<style name="RedTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">@color/white</item>
</style>
<style name="GrayTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">@color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但是我有一种用于Header TextViews的样式.如果我使用的是RedTheme,我希望样式HeaderFont的textColor为红色,如果是GrayTheme,我希望HeaderFont textColor为灰色,而不必修改访问此HeaderFont样式的各个xml文件.
<style name="HeaderFont" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/gray</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我一直在寻找一个优雅的解决方案,但一直找不到任何东西.想法?