如何使用python-pptx更改形状内的字体颜色?

时间:2019-01-04 06:24:06

标签: python python-pptx

我正在尝试使用Python中的<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/rvTimeBar" android:layout_width="match_parent" android:layout_height="60dp" android:nestedScrollingEnabled="false" android:orientation="horizontal" app:layoutManager="android.support.v7.widget.LinearLayoutManager" /> <ScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" tools:context=".MainActivity"> <android.support.v7.widget.RecyclerView android:id="@+id/rvChannel" android:layout_width="100dp" android:layout_height="wrap_content" android:background="@color/colorPrimary" android:orientation="vertical" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:listitem="@layout/row_channel" /> <HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="100dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/rvProgramme" android:layout_width="match_parent" android:layout_height="wrap_content" android:nestedScrollingEnabled="false" android:orientation="vertical" app:layoutManager="android.support.v7.widget.LinearLayoutManager" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:listitem="@layout/row_programme" /> </LinearLayout> </HorizontalScrollView> </RelativeLayout> </ScrollView> </LinearLayout> </layout> 模块创建一些形状。

我已经创建了形状,但是无法编辑形状中文本的字体颜色。默认情况下,它显示为白色。我正在尝试查看如何更改文本颜色。下面给出的是我到目前为止构建的:

public class HomeActivity extends AppCompatActivity implements OnLoadMoreListener {
    ActivityHomeBinding binding;
    HomeViewModel viewModel;
    private ChannelAdapter adapter;
    private ProgrammeAdapter programmeAdapter;
    private TimeBarAdapter timeBarAdapter;
    private int serialSublistEndIndex = 30;
    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_home);
        viewModel = ViewModelProviders.of(this).get(HomeViewModel.class);
        timeBarAdapter = new TimeBarAdapter();
        timeBarAdapter.setTimeBarList(Arrays.asList(getResources().getStringArray(R.array.timeBarList)));
        adapter = new ChannelAdapter(this);
        programmeAdapter = new ProgrammeAdapter();
        LinearLayoutManager llm = new LinearLayoutManager(this);
        llm.setOrientation(LinearLayoutManager.VERTICAL);
        binding.rvChannel.setLayoutManager(llm);
        binding.rvChannel.setAdapter(adapter);
        binding.rvProgramme.setAdapter(programmeAdapter);
        binding.rvTimeBar.setAdapter(timeBarAdapter);
        viewModel.fetchChannelData();
        viewModel.channelLiveData.observe(this, new Observer<List<ChannelData>>() {
            @Override
            public void onChanged(@Nullable List<ChannelData> channelData) {
                if (viewModel.channelLiveData.getValue() != null &&
                        viewModel.channelLiveData.getValue().subList(0, 40).size() >= 0) {
                    viewModel.fetchSerialData();
                }
            }
        });
        viewModel.serialResponseLiveData.observe(this, new Observer<List<SerialResponse>>() {
            @Override
            public void onChanged(@Nullable List<SerialResponse> responses) {
                if (responses != null && responses.size() > 0) {
                    viewModel.setSerialMutableList(viewModel.channelLiveData.getValue().subList(0, 40));
                    adapter.setChannelDataList(viewModel.channelLiveData.getValue().subList(0, 40));
                    programmeAdapter.setChannelDataList(viewModel.channelLiveData.getValue().subList(0, 40), viewModel);
                }
            }
        });

        binding.rvChannel.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                Log.v("onScrolled", "onScrolled");
            }
        });
        binding.setLifecycleOwner(this);
    }
    @Override
    public void onLoadMore(int position) {
        adapter.setChannelDataList(viewModel.channelLiveData.getValue().subList(position + 1, position + 11));
    }
}

1 个答案:

答案 0 :(得分:0)

看看the documentation,您应该可以在代码中添加一行(在底部):

font.color.rgb = RGBColor(0x00, 0x00, 0x00)        # this would be black

注意:请记住,要使用RGBColor,必须将其导入:

from pptx.dml.color import RGBColor