【问题标题】:Set Navigation Bar / Action Bar color from within the App (Android)从应用程序中设置导航栏/操作栏颜色(Android)
【发布时间】:2015-09-25 16:28:59
【问题描述】:

我已经设置了一个带有一个 EditText 和一个 Button 的 Activity,我正在尝试执行以下操作:用户在 EditText 中键入十六进制颜色,按下 Button,然后 NavBar/ActionBar 将其颜色更改为键入的值。

在我发现的应用程序中更改它们的唯一方法是将 NavBar/ActionBar 的样式更改为预制样式,但我希望能够将其设置为自定义颜色。

public class VisualTweaks extends Activity implements View.OnClickListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_visual_tweaks);

        Button colorButton = (Button) findViewById(R.id.countButton);
        EditText colorEditText = (EditText) findViewById(R.id.colorEditText);

        colorButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (android.os.Build.VERSION.SDK_INT >= 21)
            getWindow().setNavigationBarColor(getResources().getColor(R.color.navigationbar_color));
    }
}

【问题讨论】:

    标签: java android colors action


    【解决方案1】:

    这是我为 actionBar 找到的快速修复:

    getActionBar().setBackgroundDrawable(new ColorDrawable(0xff00DDED));
    getActionBar().setDisplayShowTitleEnabled(false);
    getActionBar().setDisplayShowTitleEnabled(true);
    

    【讨论】:

      【解决方案2】:
      ActionBar actionBar;
      
       actionBar = getActionBar(); 
       ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#93E9FA"));     
       actionBar.setBackgroundDrawable(colorDrawable);
      

      你的导航栏也可以使用相同的 colorDrawable

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-13
        • 2013-10-03
        • 2018-10-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多