如何在Java中更改setText的字体

时间:2019-05-15 23:54:20

标签: java android

我向用户展示了其他人最近一次看到的日期和时间。该文本当前为粗体,我不希望其为粗体。如何在Java中使文本固定?

我尝试过

Font myFont = new Font("Serif", Font.BOLD, 12);

userLastSeen.setText( date + " " + time );
b.setFont(userLastSeen);

5 个答案:

答案 0 :(得分:0)

看起来像这样可以帮助您

function addToDatabase(Request $request)
{
    $ig = new \InstagramAPI\Instagram();

    foreach ($request->file() as $file) {
        foreach ($file as $f) {
            $f->move(storage_path('images'), time().'_'.$f->getClientOriginalName());
        }
    }
    $files = storage_path('images/1557963184_b_near-east-university-1489.tU9IR.png');
    dump($files); 
    $metadata = [
        'caption' => 'My awesome caption',
        'location' => $files, // $location must be an instance of /Model/Location class
        'photoFilename'=>'huy',
      ];
      $metadata = ['caption' => 'My awesome caption'];

$ig->timeline->uploadPhoto('1557963184_b_near-east-university- 
1489.tU9IR.png', $metadata);

return "Успех";    
 }

答案 1 :(得分:0)

尝试userLastSeen.setTypeface(Typeface.DEFAULT);

答案 2 :(得分:0)

为什么不将其设置为XML?

将其放入<Textview>

android:textStyle="normal"

或者您可以尝试

textView.setTypeface(null, Typeface.NORMAL);
textView.setTypeface(null, Typeface.BOLD);
textView.setTypeface(null, Typeface.ITALIC);

答案 3 :(得分:0)

将字体设置为文本字段应该可以。 为了使文本居中对齐,请使用textfield.setHorizo​​ntalAlignment(JTextField.CENTER); 以下代码可能会帮助您:

let counter = 0;
function createData(projectId, projectName, projectStatus, totalCost, paymentStatus, clientName, email, phone) {
    counter += 1;
    return { id: counter, projectId, projectName, projectStatus, totalCost, paymentStatus, clientName, email, phone };
}

function desc(a, b, orderBy) {
    if (b[orderBy] < a[orderBy]) {
        return -1;
    }
    if (b[orderBy] > a[orderBy]) {
        return 1;
    }
    return 0;
}

function getSorting(order, orderBy) {
    return order === 'desc' ? (a, b) => desc(a, b, orderBy) : (a, b) => -desc(a, b, orderBy);
}

class AllTable extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            order: 'asc',
            orderBy: 'userName',
            data: [],
        };
    }

componentDidMount() {
        API.get('url')
            .then(({ data }) => {
                this.setState({
                    data: data.response.map(
                        job => (
                            createData(
                                job.project_id,
                                parseFloat(job.total),
                                job.payment_status,
                            )
                        )
                    )
                })
            })
            .catch((err) => {
                console.log("AXIOS ERROR: ", err);
            })
    }

handleRequestSort = (event, property) => {
        const orderBy = property;
        let order = 'desc';
        if (this.state.orderBy === property && this.state.order === 'desc') {
            order = 'asc';
        }
        this.setState({ order, orderBy });
    };

    render(){
      return(
          {data
            .sort(getSorting(order, orderBy))
               .map(n => {
                  return (
                    <TableRow
                        hover
                        tabIndex={-1}
                        key={n.id}
                    >
                       <TableCell className={classes.tdWidth}><div className={classes.cellWidth}>${n.totalCost}</div></TableCell>
                       <TableCell className={classes.tdWidth}><div className={classes.cellWidth}>{n.paymentStatus}</div></TableCell>
                    </TableRow>
           })}
      )
}

}

答案 4 :(得分:0)

将常规(粗体,普通等)字体复制到Assets / fonts文件夹中 定义字体:

Typeface fontName = Typeface.createFromAsset(getAssets(), "fonts/tahoma.ttf");

现在您可以像这样设置视图的字体:

your_textview_name.setTypeface(fontName);