以编程方式设置TextView的主题属性

时间:2018-05-18 11:41:12

标签: android material-design

我有一个带有主题的TextView,ActionButtonBlue。如何在运行时将TextView的import React, { Component } from 'react'; import LocalesProvider from './Providers/LocalesProvider.js'; import { NavLink, HashRouter } from "react-router-dom"; class Sidebar extends Component { constructor(props) { super(props); } buildLocaleLinks (locales, uri) { if (!this.props.isReady) { return 'Loading...'; } if (!locales.length) { return null; } return locales.map(function (locale) { return ( <li key={'navigation.translate.' + locale.props.key}> <NavLink replace to={'/' + uri + '/' + locale.props.key}> {locale.props.key} </NavLink> </li> ); }) } render () { return ( <HashRouter> <aside className="menu"> <p className="menu-label"> Menu </p> <ul className="menu-list"> <li>Translate</li> <li> <ul> <LocalesProvider.Consumer> {locales => ( this.buildLocaleLinks(locales, 'translate') )} </LocalesProvider.Consumer> </ul> </li> <li>Validate</li> <li> <ul> <LocalesProvider.Consumer> {locales => ( this.buildLocaleLinks(locales, 'validate') )} </LocalesProvider.Consumer> </ul> </li> </ul> </aside> </HashRouter> ); } } export default Sidebar; 从ActionButtonBlue更改为ActionButtonYellow?方法theme适用于setTextAppearance()属性,但不适用于style属性。

theme

styles.xml:

<TextView
    android:id="@+id/blueTV"
    android:theme="@style/ActionButtonBlue"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

blueTV = (TextView) findViewById(R.id.blueTV);

blueTV = new TextView(getApplicationContext(), null, R.style.ActionButtonBlue);