Android - set TextView TextStyle programmatically?

前端 未结 11 635
南旧
南旧 2020-12-02 05:04

Is there a way to set the textStyle attribute of a TextView programmatically? There doesn\'t appear to be a setTextStyle() method.

11条回答
  •  难免孤独
    2020-12-02 05:38

    I´ve resolved it with two simple methods.

    Follow the explanation.

    My existing style declaration:

    
    

    My Android Java code:

        TextView locationName = new TextView(getSupportActivity());
        locationName.setId(IdGenerator.generateViewId());
        locationName.setText(location.getName());
        locationName.setLayoutParams(super.centerHorizontal());
        locationName.setTextSize(24f);
        locationName.setPadding(0, 0, 0, 15);
        locationName.setTextColor(getResources().getColor(R.color.Church_Grey));
        locationName.setShadowLayer(3, 1, 1,  getResources().getColor(R.color.Shadow_Church));
    

    Regards.

提交回复
热议问题