findViewByID仅在某些Samsung Android Nougat设备上返回null

时间:2017-08-09 15:09:02

标签: android titlebar android-7.0-nougat

我已按照

加载自定义标题栏的活动
@Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



            requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
            final RelativeLayout frameLayout =  new RelativeLayout(this);

            setContentView(frameLayout);
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
                    R.layout.lfpdftitlebar_v2);

            View v = findViewById(R.id.pdftoolbar);
            //v is Null only on some Android 7 devices


}

和R.id.pdftoolbar

 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pdftoolbar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/pdftoolbar_all"
            android:layout_width="fill_parent"
            android:layout_height="45dp"
            android:background="@color/light_blue"
            android:descendantFocusability="beforeDescendants"
            android:elevation="5dp"
            android:orientation="horizontal" >
        </RelativeLayout>

    </LinearLayout>

仅在某些Android 7设备上,我无法访问布局R.layout.window_title中定义的View,因为此对象上的this.findViewById或getWindow()。findViewById()返回 null

0 个答案:

没有答案