简体   繁体   English

Android-使用onclick调用style.xml

[英]Android - Call style.xml with onclick

I have this code 我有这个代码

<style name="large">
    <item name="android:textSize">20dp</item>
</style>

My layout 我的布局

<Button
    android:id="@+id/button_s"
    android:text="@string/button_small" />

<Button
    android:id="@+id/button_l"
    android:text="@string/button_large" />

<TextView
    android:id="@+id/textView1"
    android:text="Hello World" />

I want when i click button large, it call style large . 我想当我单击较大的按钮时,将其称为样式 Please help me! 请帮我!

Try this, 尝试这个,

Button button = (Button)findViewById(R.id.button_l);
final TextView textViewTitle = (TextView) findViewById(R.id.textView1);

button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        if (Build.VERSION.SDK_INT < 23) {
            textViewTitle.setTextAppearance(ActivityName.this, R.style.large);
        } else {
            textViewTitle.setTextAppearance(R.style.large);
        }
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM