小编Son*_*hja的帖子

如何在Android中为整个应用程序设置自定义字体?

是否可以在Android应用程序中设置自定义字体?

我尝试了这里发布的内容,但我不知道我的extends Application课程在哪里......

有帮助吗?

编辑:

我尝试了以下方法:

  • 添加资源文件夹并在其中插入字体,如下所示:

在此输入图像描述

  • 添加一个扩展自的新类 Application

  • 从我的电话中调用这个新课程AndroidManifest.xml.

  • 我按照我的风格添加了它.

MyApp.java:

public class MyApp extends Application {
  @Override
  public void onCreate() {
     super.onCreate();
    FontsOverride.setDefaultFont(this, "DEFAULT", "raleway_regular.ttf");
    //  This FontsOverride comes from the example I posted above
  }
  }
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml中:

<application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:supportsRtl="true"
      android:name=".MyApp"
      android:theme="@style/AppTheme">
     ....
Run Code Online (Sandbox Code Playgroud)

styles.xml:

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:fontFamily">default</item>
 </style>
Run Code Online (Sandbox Code Playgroud)

但我的字体仍然没有变换......任何想法?

然后MyApp调用该类.但对我的字体没有影响......

EDIT2:我意识到在为按钮设置自定义样式后,我的按钮会应用自定义字体.这是我的自定义按钮样式:

<style name="MyButtonStyle" parent="Widget.AppCompat.Button">
    <item name="textAllCaps">false</item>
    <item name="android:textAllCaps">false</item>
</style>
Run Code Online (Sandbox Code Playgroud)

以下是它现在的样子:

在此输入图像描述

所以:我的按钮正在应用样式,但不是TextView.有关为什么我的自定义字体没有应用于应用程序中的所有项目的任何想法?

android

68
推荐指数
7
解决办法
6万
查看次数

根据分辨率更改字体大小

我正在开发一个网页,它为不同的段落使用不同的大小,等等......等等.我正在使用em尺寸:font-size:2em; , 举个例子.但是,当我将屏幕分辨率更改为较低的分辨率时,我希望将该分辨率调整为较小的分辨率.

为此,我尝试了这段代码:

<script>
        if ( screen.width > 1600)
        {
            document.write('<style>#centered h1 { font-size: 2em; } </style>');
        }
        else if (screen.width <= 1600 && screen.width >= 1360)
        {
            document.write('<style>#centered h1 { font-size: 1.7em; } </style>');
        }
        else if (screen.width < 1360 && >= 1024)
        {
            document.write('<style>#centered h1 { font-size: 1.4em; } </style>');
        }
        else
        {
            document.write('<style>#centered h1 { font-size: 0.8em; } </style>');
        }
    </script>
Run Code Online (Sandbox Code Playgroud)

第一:它不起作用......
第二:我认为应该有更清洁的方法这样做......

所以,问题是:如何对我的字体使用不同的大小或如何使它们针对不同的分辨率进行调整?

有人可以帮忙吗?谢谢!

html css jquery screen-resolution

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

在Java/Android中抛出自定义异常

我正在开发一个自定义的Exception类,其中我有以下构造函数:

public class UserException extends Exception
{
    string message;
    public UserException() {
        super();
    }

    public UserException(String message, Throwable cause)
    {
        super(message, cause);

        this.cause = cause;
        this.message = message;
    }
}
Run Code Online (Sandbox Code Playgroud)

我创建了一个新的自定义异常,如下所示:

private Camera.PreviewCallback SetPreviewCallBack() throws UserException {
    .......
    // Something went wrong
    throw new UserException("Something failed.", new Throwable(String.valueOf(UserExceptionType.CaptureFailed)));
 }
Run Code Online (Sandbox Code Playgroud)

但是,当我插入throw new UserException(...)它时,它告诉我用它包围try/catch!! 这不是主意,不是吗?当我需要抛出自定义异常时,我想抛出自定义异常,而不会new Exceptions使用更多的try/catch子句.

那么,我做错了什么?我误解了什么?

java android exception-handling exception

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

如何验证PasswordBox WPF

我正在尝试对a进行验证PasswordBox.为了进行验证,我按照此链接显示了如何验证TextBox.

问题来了PasswordBoxes.由于Password安全原因它不可绑定,我尝试在此链接后进行绑定(此处也解释了CodeProject用户).

所以,显然,太棒了!我可以绑定我PasswordBoxPassword属性,所以我可以绑定我的验证.但它忽略了我......

这是TextBox我使用的常规并且工作正常:

<local:ErrorProvider Grid.Column="1" Grid.Row="2" >
    <TextBox Width="160" 
          HorizontalAlignment="Left" 
           Name="textBoxUserPass" 
           Text="{Binding Path=Password, UpdateSourceTrigger=Explicit}" />
 </local:ErrorProvider>
Run Code Online (Sandbox Code Playgroud)

这是PasswordBox我试图模拟的:

<local:ErrorProvider Grid.Column="1" Grid.Row="2" >
      <PasswordBox Width="160"
          HorizontalAlignment="Left"
          Name="textBoxUserPass"
          local:PasswordBoxAssistant.BindPassword="True"
          local:PasswordBoxAssistant.BoundPassword="{Binding Path=Password, UpdateSourceTrigger=Explicit}" />
 </local:ErrorProvider>
Run Code Online (Sandbox Code Playgroud)

这就是我BindingExpression每个人的方式TextBox:

BindingExpression beUserName = textBoxUserName.GetBindingExpression(TextBox.TextProperty);
if (beUserName != null) beUserName.UpdateSource();
Run Code Online (Sandbox Code Playgroud)

这就是我得到它的方式PasswordBox:

BindingExpression bePassword = textBoxUserPass.GetBindingExpression(PasswordBoxAssistant.BoundPassword);
if (bePassword != null) bePassword.UpdateSource(); …
Run Code Online (Sandbox Code Playgroud)

c# validation wpf

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

如何在XAML中填充ComboBox

我正在尝试ComboBox用一对String,Value填充一个.我在代码背后做了这样的事情:

listCombos = new List<ComboBoxItem>();
item = new ComboBoxItem { Text = Cultures.Resources.Off, Value = "Off" };
listCombos.Add(item);
item = new ComboBoxItem { Text = Cultures.Resources.Low, Value = "Low" };
listCombos.Add(item);
item = new ComboBoxItem { Text = Cultures.Resources.Medium, Value = "Medium" };
listCombos.Add(item);
item = new ComboBoxItem { Text = Cultures.Resources.High, Value = "High" };
listCombos.Add(item);
combo.ItemsSource = listCombos;
Run Code Online (Sandbox Code Playgroud)

ComboBoxItem:

public class ComboBoxItem
{
    public string Text { get; set; }
    public object Value { …
Run Code Online (Sandbox Code Playgroud)

wpf xaml combobox

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

必须加载PHP扩展"curl"

我正在尝试在我的服务器上安装Magento,当我进入"配置"时,安装启动:必须加载PHP扩展"curl".

我已经检查了我的php.ini,并且没有注释extension = php_curl.dll.对于Apache和PHP文件夹.我还检查了我的Wamp经理,它看起来像这样:

我的PHP信息.

所以我猜我的php_curl运行正常...但是当我安装Magento时我仍然收到相同的消息:

我的Magento安装.

什么是错的?

magento magento-1.7

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

片段中的Android Camera预览

到目前为止,我有一个完整的工作代码插入相机,以查看前置摄像头的预览.

我现在要做的是让相机在里面工作Fragment.

完整代码:

MainActivity.java

public class MainActivity extends Activity {

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

    setContentView(R.layout.fragment_main);

    getFragmentManager().beginTransaction().add(R.id.mainLayout, new CameraExtractionFragment()).commit();
}
}
Run Code Online (Sandbox Code Playgroud)

CameraExtractionFragment.java

public class CameraExtractionFragment extends Fragment {

private CameraExtraction mCameraExtraction;
Camera mCamera;
int mNumberOfCameras;
int cameraId;
int rotation;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mCameraExtraction = new CameraExtraction(
            this.getActivity().getBaseContext(), 
            this.getActivity().getWindowManager().getDefaultDisplay().getRotation()
            );

    // Find the total number of cameras available
    mNumberOfCameras = Camera.getNumberOfCameras();

    // Find the ID of the rear-facing ("default") camera
    CameraInfo cameraInfo = …
Run Code Online (Sandbox Code Playgroud)

android android-camera android-fragments

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

Wix和Visual Studio安装程序之间的区别

我正在使用WPF开发Visual Studio应用程序,但现在是我必须选择安装程序的时刻.

我需要我的项目能够在GAC和注册表上编写,但我不确定我是否应该使用Visual Studio安装程序或Wix ...我无法在Google上找到确切地说明两者之间差异的信息他们.

我发现Wix更完整,但我找不到任何指定一个或另一个之间真正差异的文章......

任何人都可以帮我找到更具体的信息或在两者之间做出选择吗?

编辑:对不起,我指定:

我正在使用Visual Studio 2010专业版.

installer wix visual-studio-2010 visual-studio

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

WPf中ListView的平铺视图

如何ListView在WPF中模拟tile视图?

在此输入图像描述

我正在尝试这里显示的例子.但我无法找到正确的解决方案...但我不想使用该解决方案,因为它太具体了.那么如何成功实现这一目标呢?

编辑:我现在正在尝试这个似乎工作...

<ListBox ItemsSource="{Binding Path=ListObservableUsers, ElementName=AdminWindow}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Vertical">
                    <Image Source="{Binding Path=Picture}"></Image>
                    <Label Content="{Binding Path=Dni}"></Label>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
Run Code Online (Sandbox Code Playgroud)

哪里ElementName=AdminWindow来自<Window .... x:Name="AdminWindow"

我创造了自己的 ObservableCollection<MyUser>

    public class MyUser
{
    public MyUser(int id, string dni, Bitmap picture)
    {
        Id = id;
        Dni = dni;
        Image img = new Image();
        FPhiMultipleSources.FromBitmapImage(img, picture);
        Picture = img.Source;
    }

    public int Id { get; set; }
    public string Dni { get; set; }
    public …
Run Code Online (Sandbox Code Playgroud)

wpf listview wpf-controls

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

如何更改Magento的列数

好吧,这个问题似乎很容易解决,但它让我不知所措......

我在Magento Web上有一些类别,每个类别都有一些产品.我希望它们显示为4列计数,但它总是显示为3列计数,如下所示:

在此输入图像描述

我试过这个:在app/desing/frontend/default/mytheme/layout/catalog.xml上,我修改了这段代码:

<!--
Category default layout
-->

<catalog_category_default translate="label">
    <label>Catalog Category (Non-Anchor)</label>
    <reference name="left">
        <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
    </reference>
    <reference name="content">
        <block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
            <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
                <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                    <block type="page/html_pager" name="product_list_toolbar_pager"/>
                    <!-- The following code shows how to set your own pager increments -->
                    <!--
                        <action method="setDefaultListPerPage"><limit>4</limit></action>
                        <action method="setDefaultGridPerPage"><limit>9</limit></action>
                        <action method="addPagerLimit"><mode>list</mode><limit>2</limit></action>
                        <action method="addPagerLimit"><mode>list</mode><limit>4</limit></action>
                        <action method="addPagerLimit"><mode>list</mode><limit>6</limit></action>
                        <action method="addPagerLimit"><mode>list</mode><limit>8</limit></action>
                        <action method="addPagerLimit" translate="label"><mode>list</mode><limit>all</limit><label>All</label></action>
                    -->
                </block>
                <action method="setColumnCount"><columns>4</columns></action>
                <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
                <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
                <action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action> …
Run Code Online (Sandbox Code Playgroud)

magento magento-1.7

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